This is awesome!! Thank you so much, I needed to fix my infinite scrolling collection view so you came in just in time .
I have a question though, why instruct the tableView to render ALL of the contents? Would this still work if we updated the size of the datastore as the new items come in from the request? In my case showing empty cells is not optimal nor desired.
Thanks, hope to hear soon!
@lorenzoboaro Can you please help with this when you get a chance? Thank you - much appreciated! :]
@caquillo07 Thanks very much for your question!
The point of rendering all of the contents is to avoid paging. You want to know ahead of time how much data is being received, so you’re able to prepare the UITableView how many cells it needs to display, before they appear to the user.
Your case of, “showing empty cells is not optimal or desired” is the situation for everyone No one wants to wait, nor see an empty UITableViewCell when they are scrolling. Because we’re using UITableView’s prefetch methods, these cells are prepared ahead of time, and the user should see a smooth scrolling experience. The empty cells with a spinner appear depend on a variety of factors:
- How much data is being downloaded from the server
- How fast is the user scrolling
- How fast the network connection is
In the case of dealing with images from the server, it would make sense for you to say, cache the images locally so that unnecessary network calls are not made once you’ve downloaded them once already. The key to remember here is that you’re trying do the prefetch the data in the background while rendering the UI to the user on the main thread, thus trying to achieve a seamless experience for the user. In your solution, what you’re suggesting should be possible, however, I think you’re creating more work for yourself than necessary since you’ll always be updating the internal datastore every time the user scrolls.
I hope this helps!
All the best!
if I may add to the response by @syedfa,
- From the users perspective, continuous scrolling is all about a smooth experience on the device
- From the developer’s perspective, it is about providing both the smooth experience on the front end and also ensuring that the backend supports the data retrieval for the same.
So, as a developer you need to pull all the good practices to ensure you use things like caching, queues, background threads, pre-fetching, etc
If you have more data, you can pre-fetch or prepare for more related data accordingly.
The materials to download with this example do not seem to have the same code. For example searching the downloaded materials for: “DispatchQueue.main.” yields no results.
@imaitland Thanks for your feedback. The code you are referring to is located in
ModeratorsViewModel Swift file (see attached image).
For any problems or clarifications let me know.
This is a great tutorial for Infinite Scrolling UITableView.
By the way, I am wondering why should we use displayName.html2String but not displayName in the init(from decoder: Decoder) of Moderator struct.
Find Moderators is not enabling at all the time. can you please help me with it @lorenzoboaro
@wtj123 Thanks for your feedback.
This is due to the fact that
displayName could contain HTML characters that needs to be transformed.
Try yourself using just
displayName instead of
displayName.html2String. You can use math as the value in the input field.
@sathyac, thanks for reading the tutorial. Could you tell me in which situation you find this behavior?
From the beginging itself its not working @lorenzoboaro
@sathyac You should insert some text, e.g. math, otherwise the button remains disabled.
I got so confused after trying to implement this in my own project that after 4 month of learning iOS programming i decided to quit
Oh no. How come? Every field, every technology, every area of study has roadblocks on your path to learning. If you’re not stuck, you’re not challenging yourself. Please do not give up, but rather, be persistent, ask others around you, post your questions online, and eventually, you will get the help you need
@onlygod Please let us know what don’t you understand exactly when you get a chance. Thank you!
This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!