Pagination code being triggered upon launch instead of when user reaches bottom of page
I'm trying to implement an infinite scroll/pagination feature to a table view. I use scrollViewDidScroll
to measure when the user reaches the bottom of the page, which then triggers a function to fetch the next batch of data. However I think the measurements are off because my fetchMoreEvents
function is being triggered upon the launch of the app.
This is the pagination code (scrollViewDidScroll
and fetchMoreEvents
):
func fetchMoreEvents() {
fetchingMore = true
var page = 1
page += 1
let seatGeekApiUrl = URL(string: "https://api.seatgeek.com/2/events?venue.state=NY&page=(page)&client_id=MTM5OTE0OTd8MTU0MjU2NTQ4MC4z")!
fetchData(url: seatGeekApiUrl) { (result: FetchResult<Welcome>) -> (Void) in
switch result {
case .success(let object): self.eventData.append(contentsOf: object.events)
print("neventData: nn(self.eventData)")
case .failure(let error):
print("nError decoding JSON: nn(error)")
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
print("nFetching next batch of events: (Page (page))n")
}
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offsetY = scrollView.contentOffset.y
let contentHeight = scrollView.contentSize.height
if offsetY > contentHeight - scrollView.frame.height {
if !fetchingMore {
fetchMoreEvents()
}
}
}
Once fetchMoreEvents
is triggered, I have it append my eventData
array with the next page of results and reload the table view. My print statement confirms that it fetches page 2 of the data, but like I said that happens immediately instead of when I scroll down the page. Also, it never gets triggered again.
Is this an issue with the measurements in scrollViewDidScroll
, or am I going wrong somewhere else?
These are the table view methods if they're applicable here:
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return eventData.count
} else if section == 1 && fetchingMore {
return 1
}
return 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "eventsCell", for: indexPath) as! EventsTableViewCell
let event = eventData[indexPath.row]
// Labels
cell.eventNameLabel.text = event.title
cell.eventVenueLabel.text = event.venue.nameV2
cell.eventAddressLabel.text = event.venue.address
cell.eventTimeLabel.text = dateFormatter.string(from: event.dateTimeLocal)
// Image
if let urlString = event.performers[0].image, let imageURL = URL(string: urlString) {
ImageService.getImage(url: imageURL) { (image) in
cell.eventImageView.image = image
}
}
else {
cell.eventImageView.image = UIImage(named: "noImageFound")
}
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "loadingCell", for: indexPath) as! LoadingCell
cell.spinner.startAnimating()
return cell
}
}
ios swift uitableview
add a comment |
I'm trying to implement an infinite scroll/pagination feature to a table view. I use scrollViewDidScroll
to measure when the user reaches the bottom of the page, which then triggers a function to fetch the next batch of data. However I think the measurements are off because my fetchMoreEvents
function is being triggered upon the launch of the app.
This is the pagination code (scrollViewDidScroll
and fetchMoreEvents
):
func fetchMoreEvents() {
fetchingMore = true
var page = 1
page += 1
let seatGeekApiUrl = URL(string: "https://api.seatgeek.com/2/events?venue.state=NY&page=(page)&client_id=MTM5OTE0OTd8MTU0MjU2NTQ4MC4z")!
fetchData(url: seatGeekApiUrl) { (result: FetchResult<Welcome>) -> (Void) in
switch result {
case .success(let object): self.eventData.append(contentsOf: object.events)
print("neventData: nn(self.eventData)")
case .failure(let error):
print("nError decoding JSON: nn(error)")
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
print("nFetching next batch of events: (Page (page))n")
}
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offsetY = scrollView.contentOffset.y
let contentHeight = scrollView.contentSize.height
if offsetY > contentHeight - scrollView.frame.height {
if !fetchingMore {
fetchMoreEvents()
}
}
}
Once fetchMoreEvents
is triggered, I have it append my eventData
array with the next page of results and reload the table view. My print statement confirms that it fetches page 2 of the data, but like I said that happens immediately instead of when I scroll down the page. Also, it never gets triggered again.
Is this an issue with the measurements in scrollViewDidScroll
, or am I going wrong somewhere else?
These are the table view methods if they're applicable here:
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return eventData.count
} else if section == 1 && fetchingMore {
return 1
}
return 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "eventsCell", for: indexPath) as! EventsTableViewCell
let event = eventData[indexPath.row]
// Labels
cell.eventNameLabel.text = event.title
cell.eventVenueLabel.text = event.venue.nameV2
cell.eventAddressLabel.text = event.venue.address
cell.eventTimeLabel.text = dateFormatter.string(from: event.dateTimeLocal)
// Image
if let urlString = event.performers[0].image, let imageURL = URL(string: urlString) {
ImageService.getImage(url: imageURL) { (image) in
cell.eventImageView.image = image
}
}
else {
cell.eventImageView.image = UIImage(named: "noImageFound")
}
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "loadingCell", for: indexPath) as! LoadingCell
cell.spinner.startAnimating()
return cell
}
}
ios swift uitableview
it looks to me like the frames aren't what you expect in scrollViewDidScroll. possibly called before the views are fully laid out?
– scord
Nov 27 '18 at 19:04
add a comment |
I'm trying to implement an infinite scroll/pagination feature to a table view. I use scrollViewDidScroll
to measure when the user reaches the bottom of the page, which then triggers a function to fetch the next batch of data. However I think the measurements are off because my fetchMoreEvents
function is being triggered upon the launch of the app.
This is the pagination code (scrollViewDidScroll
and fetchMoreEvents
):
func fetchMoreEvents() {
fetchingMore = true
var page = 1
page += 1
let seatGeekApiUrl = URL(string: "https://api.seatgeek.com/2/events?venue.state=NY&page=(page)&client_id=MTM5OTE0OTd8MTU0MjU2NTQ4MC4z")!
fetchData(url: seatGeekApiUrl) { (result: FetchResult<Welcome>) -> (Void) in
switch result {
case .success(let object): self.eventData.append(contentsOf: object.events)
print("neventData: nn(self.eventData)")
case .failure(let error):
print("nError decoding JSON: nn(error)")
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
print("nFetching next batch of events: (Page (page))n")
}
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offsetY = scrollView.contentOffset.y
let contentHeight = scrollView.contentSize.height
if offsetY > contentHeight - scrollView.frame.height {
if !fetchingMore {
fetchMoreEvents()
}
}
}
Once fetchMoreEvents
is triggered, I have it append my eventData
array with the next page of results and reload the table view. My print statement confirms that it fetches page 2 of the data, but like I said that happens immediately instead of when I scroll down the page. Also, it never gets triggered again.
Is this an issue with the measurements in scrollViewDidScroll
, or am I going wrong somewhere else?
These are the table view methods if they're applicable here:
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return eventData.count
} else if section == 1 && fetchingMore {
return 1
}
return 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "eventsCell", for: indexPath) as! EventsTableViewCell
let event = eventData[indexPath.row]
// Labels
cell.eventNameLabel.text = event.title
cell.eventVenueLabel.text = event.venue.nameV2
cell.eventAddressLabel.text = event.venue.address
cell.eventTimeLabel.text = dateFormatter.string(from: event.dateTimeLocal)
// Image
if let urlString = event.performers[0].image, let imageURL = URL(string: urlString) {
ImageService.getImage(url: imageURL) { (image) in
cell.eventImageView.image = image
}
}
else {
cell.eventImageView.image = UIImage(named: "noImageFound")
}
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "loadingCell", for: indexPath) as! LoadingCell
cell.spinner.startAnimating()
return cell
}
}
ios swift uitableview
I'm trying to implement an infinite scroll/pagination feature to a table view. I use scrollViewDidScroll
to measure when the user reaches the bottom of the page, which then triggers a function to fetch the next batch of data. However I think the measurements are off because my fetchMoreEvents
function is being triggered upon the launch of the app.
This is the pagination code (scrollViewDidScroll
and fetchMoreEvents
):
func fetchMoreEvents() {
fetchingMore = true
var page = 1
page += 1
let seatGeekApiUrl = URL(string: "https://api.seatgeek.com/2/events?venue.state=NY&page=(page)&client_id=MTM5OTE0OTd8MTU0MjU2NTQ4MC4z")!
fetchData(url: seatGeekApiUrl) { (result: FetchResult<Welcome>) -> (Void) in
switch result {
case .success(let object): self.eventData.append(contentsOf: object.events)
print("neventData: nn(self.eventData)")
case .failure(let error):
print("nError decoding JSON: nn(error)")
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
print("nFetching next batch of events: (Page (page))n")
}
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offsetY = scrollView.contentOffset.y
let contentHeight = scrollView.contentSize.height
if offsetY > contentHeight - scrollView.frame.height {
if !fetchingMore {
fetchMoreEvents()
}
}
}
Once fetchMoreEvents
is triggered, I have it append my eventData
array with the next page of results and reload the table view. My print statement confirms that it fetches page 2 of the data, but like I said that happens immediately instead of when I scroll down the page. Also, it never gets triggered again.
Is this an issue with the measurements in scrollViewDidScroll
, or am I going wrong somewhere else?
These are the table view methods if they're applicable here:
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return eventData.count
} else if section == 1 && fetchingMore {
return 1
}
return 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "eventsCell", for: indexPath) as! EventsTableViewCell
let event = eventData[indexPath.row]
// Labels
cell.eventNameLabel.text = event.title
cell.eventVenueLabel.text = event.venue.nameV2
cell.eventAddressLabel.text = event.venue.address
cell.eventTimeLabel.text = dateFormatter.string(from: event.dateTimeLocal)
// Image
if let urlString = event.performers[0].image, let imageURL = URL(string: urlString) {
ImageService.getImage(url: imageURL) { (image) in
cell.eventImageView.image = image
}
}
else {
cell.eventImageView.image = UIImage(named: "noImageFound")
}
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "loadingCell", for: indexPath) as! LoadingCell
cell.spinner.startAnimating()
return cell
}
}
ios swift uitableview
ios swift uitableview
asked Nov 27 '18 at 18:49
KingTimKingTim
5261820
5261820
it looks to me like the frames aren't what you expect in scrollViewDidScroll. possibly called before the views are fully laid out?
– scord
Nov 27 '18 at 19:04
add a comment |
it looks to me like the frames aren't what you expect in scrollViewDidScroll. possibly called before the views are fully laid out?
– scord
Nov 27 '18 at 19:04
it looks to me like the frames aren't what you expect in scrollViewDidScroll. possibly called before the views are fully laid out?
– scord
Nov 27 '18 at 19:04
it looks to me like the frames aren't what you expect in scrollViewDidScroll. possibly called before the views are fully laid out?
– scord
Nov 27 '18 at 19:04
add a comment |
1 Answer
1
active
oldest
votes
Declare an Bool as property
var isAllRowSeeked: Bool = false
Put this logic in your scrollViewDidScroll
let height = scrollView.frame.size.height
let contentYoffset = scrollView.contentOffset.y
let distanceFromBottom = scrollView.contentSize.height - contentYoffset
if distanceFromBottom < height,
self.isAllRowSeeked == true {
// you've reached the end, you are now ready to load more data
self.isAllRowSeeked = false
}
Now in cellForRowAtIndexPath
if fetchingMore == true,
isLastSectionRow(indexPath: indexPath) {// it's the last row of this section
state.isAllRowSeeked = true
return paginatorUI?.getPaginatedLoadMoreCell()
} else {
return nil
}
Add the following method
public func isLastSectionRow(indexPath: IndexPath) -> Bool {
let lastSection = tableview.dataSource?.numberOfSections?(in: tableview)
?? 1
let lastRow = tableview.dataSource?.tableView(tableview,
numberOfRowsInSection: indexPath.section)
?? 0
return lastSection == (indexPath.section+1) && lastRow == (indexPath.row+1)
}
Actually this logic is borrowed from one of my pod, which you can use. Complete code for this pagination can be found here
Tried this and the same issue is happening. As soon as I run the app the first thing printed to the console isFetching next batch of events: (Page 2)
. Then once the bottom is reached nothing else is triggered.
– KingTim
Nov 27 '18 at 18:59
Actually, I took away theif !fetchingMore
condition and it seems to have infinite scroll now, but it constantly fetches page 2 over and over. It's also triggered immediately upon launch of the app.
– KingTim
Nov 27 '18 at 19:03
i've updated the answer, actually i missed few chcking previously.
– Ratul Sharker
Nov 27 '18 at 19:06
If the answer is so bad that receives negative votes, please consider yourself to put a comment with proper reasoning.
– Ratul Sharker
Nov 28 '18 at 6:30
1
I understand, it happens to me sometimes as well and it's very frustrating. Downvotes are fine but I feel like people can at least explain what their issue is with the question or answer.
– KingTim
Nov 28 '18 at 15:34
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53506284%2fpagination-code-being-triggered-upon-launch-instead-of-when-user-reaches-bottom%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Declare an Bool as property
var isAllRowSeeked: Bool = false
Put this logic in your scrollViewDidScroll
let height = scrollView.frame.size.height
let contentYoffset = scrollView.contentOffset.y
let distanceFromBottom = scrollView.contentSize.height - contentYoffset
if distanceFromBottom < height,
self.isAllRowSeeked == true {
// you've reached the end, you are now ready to load more data
self.isAllRowSeeked = false
}
Now in cellForRowAtIndexPath
if fetchingMore == true,
isLastSectionRow(indexPath: indexPath) {// it's the last row of this section
state.isAllRowSeeked = true
return paginatorUI?.getPaginatedLoadMoreCell()
} else {
return nil
}
Add the following method
public func isLastSectionRow(indexPath: IndexPath) -> Bool {
let lastSection = tableview.dataSource?.numberOfSections?(in: tableview)
?? 1
let lastRow = tableview.dataSource?.tableView(tableview,
numberOfRowsInSection: indexPath.section)
?? 0
return lastSection == (indexPath.section+1) && lastRow == (indexPath.row+1)
}
Actually this logic is borrowed from one of my pod, which you can use. Complete code for this pagination can be found here
Tried this and the same issue is happening. As soon as I run the app the first thing printed to the console isFetching next batch of events: (Page 2)
. Then once the bottom is reached nothing else is triggered.
– KingTim
Nov 27 '18 at 18:59
Actually, I took away theif !fetchingMore
condition and it seems to have infinite scroll now, but it constantly fetches page 2 over and over. It's also triggered immediately upon launch of the app.
– KingTim
Nov 27 '18 at 19:03
i've updated the answer, actually i missed few chcking previously.
– Ratul Sharker
Nov 27 '18 at 19:06
If the answer is so bad that receives negative votes, please consider yourself to put a comment with proper reasoning.
– Ratul Sharker
Nov 28 '18 at 6:30
1
I understand, it happens to me sometimes as well and it's very frustrating. Downvotes are fine but I feel like people can at least explain what their issue is with the question or answer.
– KingTim
Nov 28 '18 at 15:34
|
show 3 more comments
Declare an Bool as property
var isAllRowSeeked: Bool = false
Put this logic in your scrollViewDidScroll
let height = scrollView.frame.size.height
let contentYoffset = scrollView.contentOffset.y
let distanceFromBottom = scrollView.contentSize.height - contentYoffset
if distanceFromBottom < height,
self.isAllRowSeeked == true {
// you've reached the end, you are now ready to load more data
self.isAllRowSeeked = false
}
Now in cellForRowAtIndexPath
if fetchingMore == true,
isLastSectionRow(indexPath: indexPath) {// it's the last row of this section
state.isAllRowSeeked = true
return paginatorUI?.getPaginatedLoadMoreCell()
} else {
return nil
}
Add the following method
public func isLastSectionRow(indexPath: IndexPath) -> Bool {
let lastSection = tableview.dataSource?.numberOfSections?(in: tableview)
?? 1
let lastRow = tableview.dataSource?.tableView(tableview,
numberOfRowsInSection: indexPath.section)
?? 0
return lastSection == (indexPath.section+1) && lastRow == (indexPath.row+1)
}
Actually this logic is borrowed from one of my pod, which you can use. Complete code for this pagination can be found here
Tried this and the same issue is happening. As soon as I run the app the first thing printed to the console isFetching next batch of events: (Page 2)
. Then once the bottom is reached nothing else is triggered.
– KingTim
Nov 27 '18 at 18:59
Actually, I took away theif !fetchingMore
condition and it seems to have infinite scroll now, but it constantly fetches page 2 over and over. It's also triggered immediately upon launch of the app.
– KingTim
Nov 27 '18 at 19:03
i've updated the answer, actually i missed few chcking previously.
– Ratul Sharker
Nov 27 '18 at 19:06
If the answer is so bad that receives negative votes, please consider yourself to put a comment with proper reasoning.
– Ratul Sharker
Nov 28 '18 at 6:30
1
I understand, it happens to me sometimes as well and it's very frustrating. Downvotes are fine but I feel like people can at least explain what their issue is with the question or answer.
– KingTim
Nov 28 '18 at 15:34
|
show 3 more comments
Declare an Bool as property
var isAllRowSeeked: Bool = false
Put this logic in your scrollViewDidScroll
let height = scrollView.frame.size.height
let contentYoffset = scrollView.contentOffset.y
let distanceFromBottom = scrollView.contentSize.height - contentYoffset
if distanceFromBottom < height,
self.isAllRowSeeked == true {
// you've reached the end, you are now ready to load more data
self.isAllRowSeeked = false
}
Now in cellForRowAtIndexPath
if fetchingMore == true,
isLastSectionRow(indexPath: indexPath) {// it's the last row of this section
state.isAllRowSeeked = true
return paginatorUI?.getPaginatedLoadMoreCell()
} else {
return nil
}
Add the following method
public func isLastSectionRow(indexPath: IndexPath) -> Bool {
let lastSection = tableview.dataSource?.numberOfSections?(in: tableview)
?? 1
let lastRow = tableview.dataSource?.tableView(tableview,
numberOfRowsInSection: indexPath.section)
?? 0
return lastSection == (indexPath.section+1) && lastRow == (indexPath.row+1)
}
Actually this logic is borrowed from one of my pod, which you can use. Complete code for this pagination can be found here
Declare an Bool as property
var isAllRowSeeked: Bool = false
Put this logic in your scrollViewDidScroll
let height = scrollView.frame.size.height
let contentYoffset = scrollView.contentOffset.y
let distanceFromBottom = scrollView.contentSize.height - contentYoffset
if distanceFromBottom < height,
self.isAllRowSeeked == true {
// you've reached the end, you are now ready to load more data
self.isAllRowSeeked = false
}
Now in cellForRowAtIndexPath
if fetchingMore == true,
isLastSectionRow(indexPath: indexPath) {// it's the last row of this section
state.isAllRowSeeked = true
return paginatorUI?.getPaginatedLoadMoreCell()
} else {
return nil
}
Add the following method
public func isLastSectionRow(indexPath: IndexPath) -> Bool {
let lastSection = tableview.dataSource?.numberOfSections?(in: tableview)
?? 1
let lastRow = tableview.dataSource?.tableView(tableview,
numberOfRowsInSection: indexPath.section)
?? 0
return lastSection == (indexPath.section+1) && lastRow == (indexPath.row+1)
}
Actually this logic is borrowed from one of my pod, which you can use. Complete code for this pagination can be found here
edited Nov 27 '18 at 19:05
answered Nov 27 '18 at 18:56
Ratul SharkerRatul Sharker
3,12911929
3,12911929
Tried this and the same issue is happening. As soon as I run the app the first thing printed to the console isFetching next batch of events: (Page 2)
. Then once the bottom is reached nothing else is triggered.
– KingTim
Nov 27 '18 at 18:59
Actually, I took away theif !fetchingMore
condition and it seems to have infinite scroll now, but it constantly fetches page 2 over and over. It's also triggered immediately upon launch of the app.
– KingTim
Nov 27 '18 at 19:03
i've updated the answer, actually i missed few chcking previously.
– Ratul Sharker
Nov 27 '18 at 19:06
If the answer is so bad that receives negative votes, please consider yourself to put a comment with proper reasoning.
– Ratul Sharker
Nov 28 '18 at 6:30
1
I understand, it happens to me sometimes as well and it's very frustrating. Downvotes are fine but I feel like people can at least explain what their issue is with the question or answer.
– KingTim
Nov 28 '18 at 15:34
|
show 3 more comments
Tried this and the same issue is happening. As soon as I run the app the first thing printed to the console isFetching next batch of events: (Page 2)
. Then once the bottom is reached nothing else is triggered.
– KingTim
Nov 27 '18 at 18:59
Actually, I took away theif !fetchingMore
condition and it seems to have infinite scroll now, but it constantly fetches page 2 over and over. It's also triggered immediately upon launch of the app.
– KingTim
Nov 27 '18 at 19:03
i've updated the answer, actually i missed few chcking previously.
– Ratul Sharker
Nov 27 '18 at 19:06
If the answer is so bad that receives negative votes, please consider yourself to put a comment with proper reasoning.
– Ratul Sharker
Nov 28 '18 at 6:30
1
I understand, it happens to me sometimes as well and it's very frustrating. Downvotes are fine but I feel like people can at least explain what their issue is with the question or answer.
– KingTim
Nov 28 '18 at 15:34
Tried this and the same issue is happening. As soon as I run the app the first thing printed to the console is
Fetching next batch of events: (Page 2)
. Then once the bottom is reached nothing else is triggered.– KingTim
Nov 27 '18 at 18:59
Tried this and the same issue is happening. As soon as I run the app the first thing printed to the console is
Fetching next batch of events: (Page 2)
. Then once the bottom is reached nothing else is triggered.– KingTim
Nov 27 '18 at 18:59
Actually, I took away the
if !fetchingMore
condition and it seems to have infinite scroll now, but it constantly fetches page 2 over and over. It's also triggered immediately upon launch of the app.– KingTim
Nov 27 '18 at 19:03
Actually, I took away the
if !fetchingMore
condition and it seems to have infinite scroll now, but it constantly fetches page 2 over and over. It's also triggered immediately upon launch of the app.– KingTim
Nov 27 '18 at 19:03
i've updated the answer, actually i missed few chcking previously.
– Ratul Sharker
Nov 27 '18 at 19:06
i've updated the answer, actually i missed few chcking previously.
– Ratul Sharker
Nov 27 '18 at 19:06
If the answer is so bad that receives negative votes, please consider yourself to put a comment with proper reasoning.
– Ratul Sharker
Nov 28 '18 at 6:30
If the answer is so bad that receives negative votes, please consider yourself to put a comment with proper reasoning.
– Ratul Sharker
Nov 28 '18 at 6:30
1
1
I understand, it happens to me sometimes as well and it's very frustrating. Downvotes are fine but I feel like people can at least explain what their issue is with the question or answer.
– KingTim
Nov 28 '18 at 15:34
I understand, it happens to me sometimes as well and it's very frustrating. Downvotes are fine but I feel like people can at least explain what their issue is with the question or answer.
– KingTim
Nov 28 '18 at 15:34
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53506284%2fpagination-code-being-triggered-upon-launch-instead-of-when-user-reaches-bottom%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
it looks to me like the frames aren't what you expect in scrollViewDidScroll. possibly called before the views are fully laid out?
– scord
Nov 27 '18 at 19:04