How to stop UITableView of reloading data and calling tableView:cellForRowAtIndexPath:? - iphone

I've got another problem my my UITableView: I dynamically load "Questions" from a XML File and show them inside cells of my UITableView, where the user can also answer them. The Problem is: if you scroll down, and then scroll up again, the answers that you typed before, just disappear. I've also noticed that UITableView calls the method tableView:cellForRowAtIndexPath: again, and that is exacty my problem, cause this method loads the questions from the XML File again so that all the answers that the User has typed get lost.
How can I keep all the cells in memory, and stop doing lazy loading of the cells?
I would appreciate any suggestions.
Thanks!

Store and preserve retrieved data in an NSMutableArray and hook this up as a data source to the table view.

Related

loading all the CollectionViewCells using willDisplay forItemAt delegate function

I have special content that I load in my CollectionViewCells from a server. This content takes a few seconds to finish loading. My issue is that once a cell is loaded, and I start scrolling my collection view, it is removed once it is not visible and needs to load again from the server, since collection​View(_:​cell​For​Item​At:​) is called again. In apple docs I see this message:
I found that note here:
https://developer.apple.com/reference/uikit/uicollectionview/1771771-isprefetchingenabled
I am not sure if I am on the correct track here, but I thought this function may help me "hack" the system to load all the cells and never deque them, so I achieve the result of scrolling my collection view back and forth and not have cells reload.
Is there a way to do that using the function collection​View(_:​will​Display:​for​Item​At:​)? Is it possible to do it otherwise? any help is appreciated.

UITableView Reloading Issue

I am in very complex issue of reloading UITableView!
I've a UITableView in which I am continuously (near by 10seconds), retrieving data from a server and showing that data in my UITableView that contains custom cells. The issue is that, when user (thats me) is scrolling through the UITableView it will crash due to an indexOutOfBound error as I am fetching data from the server the NSMutableArray will clear and fill again with data.
I also tried with a BOOL variable setting YES or NO in scrolling delegates. In this case if I scroll UITableView it will remove the cell of scroll direction, after 10 seconds it will show all cells with data.
But what I want is that, if user scrolls UITableView none of the created cell should hide! scrollEnabled is not a solution for that.
Please help me out!
Thanks :)
this is a thread unsafe code issue. data source being modified while it is being actively used.
one safe solution would be to feed all data after parsing to some DB (sqlite/Coredata) and reload the table datasource from db and call reloadData for table. this way at the time when you were using the datasource array - it wont be empty.
best of luck
if indexOutOfBound means you must check numberofrow that you specified is more than the our array receive in the cell forrowatindex. so check that.

General understanding about tableview Drawing

I have a generic question about tableview Draw and reload data, and wanted some insight from this scenario. I have a tableView which get's lazily loaded getting the data parsed from a url. Now the concern is when i select a button and move to another view, I can deselect the object from there, which will remove it from the array. Thus, when I go back to the main view of the tableView, it download's the data again and check's if the object of the further view array is there or not, therefore it set it selected the button.
My concern is, when I go back, my previous selected button is highlighted, and then it does all the computation and de-selects it when the data gets loaded. Is there anyway, I can have the tableView redrawn until the data load's everytime?
Thanks.
It Looks like that when you are downloading the data & parsing the downloaded data, you are directly passing the modified variable as a source for the tableview. Instead of it, You may store the source for the tableview into another array, which will get updated from source array if it is downloaded & parsed.
Load the tableview using the secondary array.
This is my understanding. If your problem is not resolved , please provide some piece of code for the problem.
BTW, your problem can be resolved using the above solution.

UITableView cells with both UIActivityIndicator & UIProgressView

I have a UITableView that contains several cells and some of them (the ones for files that are still uploading) have both an UIActivityIndicator and an UIProgressView. The ones for files that are finished use a different icon (instead of the activity indicator) and hide the progressview.
This table is using a NSFetchedResultsController as data source, so I get the updates on the data model and update the content.
Everything works just fine. The problem, however, is performance. Every time I call reloadData my UIActivityIndicators flicker, and it's not very smooth. Although I'm caching from the nib file, reloadData will have to calculate the new progress % for the ProgressView and I don't do anything with the ActivityIndicator other than hiding it if upload is complete.
Anybody ever tried something similar? Is there a workaround?
I was thinking about having an array of my progressview references and use that instead of calling reloadData.. not sure if this is the correct approach.
Thanks,
Fernando
When you call reloadData on the UITableView, all the cells of the table view are completely refreshed, re-assembled and redrawn. All the old ones are thrown away. This means that all the subviews of the UITableViewCells are removed and re-created too (including your UIActivityIndicator and UIProgressView). The refresh causes these views to flicker, or perhaps jump back to their start state. As there is no way of setting the frame of a UIActivityIndicator, your suggestion of restoring some progress value simply isn't possible.
Instead, perhaps you should try and engineer your "refresh" to not require a complete refresh of the table? For example, if you want to change the text of a UITextField within the view, you could simply access this text field and set the text property (no refresh is required). Or, if you want to hide your progress indicators, you could go into the appropriate object instances and set their property. You should design your app so that this is possible. Making changes this way avoids having to reload cells from scratch.
Besides the benefit of fixing your problem, using this method of updating, you should also see a large performance increase. reloadData is a very costly method to use and should be only used if it is absolutely necessary to really re-create the entire UITableView from scratch.
Hope this helps. :)

Mysterious UITableView stuck problem

I'm new to iPhone development. I'm working on a table view (default UITableView subclass) that contains complicated custom cells, with multiple subviews and controls. Scrolling is not very smooth, but I'll just leave that for now.
The question is, when I'm scrolling the table view with quick swipes, the table sometimes suddenly stops scrolling and the scroll indicator will not disappear, and I have to swipe again to make it scroll.
If the table contains very few rows, say, 5 or 6, it never stuck. The custom cell class I used is from the example provided here: http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/
Can anyone give a hint or solution to this problem? Thanks in advance.
Table cells are only created when needed, that is when they come into view and they are usually unloaded and released when they go out of view.
Put in an NSLog( #"Cell loading" ); in your cell creation code and check the console to see this happen as you scroll.
Are you using caching? The docs demonstrate how you can cache table cells to improve performance. What else are you doing when you're creating table cells? If there's any performance slow downs you should probably not have that happen while creating cells.
What I do is I generate all my content before the table loads and when cells are created all that content is simply placed into the view.
Any kind of drawing will drastically reduce performance especially if you're using transparency.
For posterity, and only valid if you are using Unity-iphone: this problem was driving me insane and I fixed it with the suggestion in this post:
http://forum.unity3d.com/threads/113815-quot-Sticky-quot-scrolling-in-UITableView-and-UIScrollView-when-interfacing-Unity-and-Obj-C
Changing the preprocessor flag to
#define USE_DISPLAY_LINK_IF_AVAILABLE 0
gave the issue a happy ending.
I'd take a look at your cellForRowAtIndexPath method - for a couple of possible problems.
If you aren't using the cell reuse that will slow things down a lot and if you are re-allocating or re-initializing your custom cells in the cellForRowAtIndexPath delegate method that can cause big performance issues.
If you post your code for that method we can give you some hints as to what might be causing it.