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.
Related
I have UIPickerView component that receive data from its datasource (NSMutableArray) which is populated from sqlite.
When user click on button new data row is added to databse.
Now I need to reload UIPickerView to display fresh data from datbase.
I know that I need to use method [storedDataPicker reloadAllComponents]; somehow but I don;t know how :( any direction, help please :)
I had a similar problem. I was loading up an array from a database in viewDidLoad that would populate the components, but I was calling to reload the picker from viewWillAppear meaning that the array that provided the datasource was not reloaded at the same time as the picker and thus not reflecting changed values. Make sure that the original data source is reloading along with the picker.
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.
This is going to be hard to demonstrate in code, but maybe you can picture it with me.
I have a view that contains two UITextFields, "title" and "descr". That same view contains two UIButtons that push another controller onto the navController to get more detail from the user about the object we're assembling and ultimately uploading to my server.
It appears that pushing another view on, doing something, and popping it back off results in the two UITextFields keeping their content VISUALLY, but the .text property of those fields becomes NULL. I've confirmed that if I do my two push-pop fields before filling in those UITextFields, I get my data when I upload, and if I do them in the opposite order, I don't. It LOOKS like there's data there, but I get nothing when I NSLog their .text properties.
Is this normal? Do I need to just design around this? Or is this as weird as it seems, and I should be looking deeper at causes of this?
I bet that you loose the references to the text fields.
Try to check 2 things:
Check if you have anything except the text (e.g. color, font, text alignment) - maybe the text view are nil
Try to write something into the text fields after the push-pop and then see if you have the .text property
Took me a while to get back to that (my BIG stack of bugs is getting ever smaller as release date approaches!), but I figured it out. On viewWillAppear, I was doing a reloadData on the table that these fields were in, and that was resetting my form fields. I stashed my data before that reloadData call and re-populated them in the tableView:cellForRowAtIndexPath: method, and we're golden.
I am new to iphone Development. I am parsing XML into a mutable array of strings which displays dynamically in a table. I am not able so see the content in the table but as soon as I scroll down the contents are displayed. Please help me out.Thanks
Can't say for certain without seeing the code but it sounds like – tableView:cellForRowAtIndexPath: returns empty cells at first. Most likely it does so because your datasource, in this case the xml parser, has not yet provided data for the cells when the table first loads.
The table only populates the visible rows and then stops. It only fetches more data when you scroll and new cells become visible. In your case, it sounds like the table has no data when it first loads but in the time it takes you to manually scroll it, it has found the data.
You probably need to call reload on the table to force it load the data. Even better, you should alter your design to make sure it has some data to display before the table itself loads. If that is not possible, you should have some placeholder information in the cells e.g. text that says "Loading Data..." and then call reload.
The problem is that when you finish parsing your XML file, you don't reload your table that is already visible.
You have to use something like [myTableView reloadData]; right after finish parsing the XML file.
Cheers,
VFN
After rendering a UITableView with a given datasource, I want to be able to switch to a different one prior to calling reloadData.
Tried doing it in the method
- (void)viewDidAppear:(BOOL)animated;
but as far as I can see this isn't called when all the visible cells are rendered.
By placing a breakpoint it seems as if nothing is actually rendered. So I must have misunderstood its actual purpose.
Is there a API callback for that or do I have to programmatically look for it?
e.g. in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
when indexPath holds the index for the last rendered cell in the tableview.
To put it into perspective (somewhat).
Suppose we have a UITableView which has a "static" datasource. Once all the static data is displayed, you want to switch to a dynamic datasource which fetches the data off the internet and reloads each row as fetched.
So I'm actually looking for the "right hook" in which to make that change from one datasource to the other.
Are there any other issues one should be concerned about?
Further clarification. I have written all the required code (e.g. an UITableViewController with the static data initialized, different datasources, background threads for the dynamic views, a delegate to notify the UITableViewController as new data is coming in) what I haven't figured out (what the question is all about) is when to actually make the switch from one datasource to the next.
When you call reloadData it forces your UITableView to re-query your data source regardless of the amount of data that is already loaded. Also, the cells that are not visible are not being loaded, so practically the last cell is only filled with data if and when you scroll down to it. If you know for sure that all your cells are visible at once, as you might have a small number of them, you might do as you suggested and call your update function when indexPath holds the index for the last cell in the tableview.
Edit:
In the light of your edits, I'm thinking that perhaps the moment you should switch data sources depends on the state of your "live" data - when you've got enough data in it to be able to show enough of it on the screen. That is, let the static data be displayed, and only switch when you've already fetched a number of values in your live data source.
Another idea might be keeping only one mutable data source, with pre-loaded static initial data. As you fetch new "live" values, you start by replacing the ones that you already have, and then continue adding new values if their number exceeds the initial number of static entries.
viewDidAppear is all about the view controller, not the table. The table reloading will never call that method.
What you want to do, is better handled either via a delegate approach or using notifications. Set up the static data set in viewDidLoad, but then right away start the background dynamic data fetch. When that fetch is complete, have the code downloading the new data call you either as a delegate, or issue a notification your the view controller with the table listens to, and reset the table view data - then you can simply call reloadData, and the cellForRow:AtIndexPath: method will be called again for the rows on the screen (reload data will also revert back to the top of the table).
UITableView load the cells lazy, in other means it only loads the cells that are visible to the user. When the user then scrolls down, the table view will load the new cells while the "old" cells will be released. There are ways to load the entire data source, but this is not recommended from Apple - since it will be heavy on the memory load of the iPhone.
viewDidAppear() is probably your best bet.
The viewWillAppear: and viewDidAppear: methods are only called when your UIViewController gets pushed on the screen (e.g. by an UINavigationContoller or UITableViewController).
What I would do in your situation is to call a method on your own view controller when your dynamic data source is ready (or whenever you intend to change the data source). In this method set the data source and then call [[self tableView] reloadData];
What you should look out for is, if you are constructing your dynamic data source in the background (which I suppose you do) then you need to call your method on the main thread using performSelectorOnMainThread: