NSMutableDictionary updates not working in UItableview - ios

I'm using *NSMutableDictionary articleDictionary as a datasource for tableview.I have different tab in tableview page, each tab i'm using different xml file [https://domain.com/api/categories/3/user/xml ] . I received different set of values in (void)viewDidUnload area but not reflect in table view .Tableview still showing old values.Please help me . Thanks
self.articleDictionary = [NSDictionary dictionaryWithContentsOfURL: [NSURL URLWithString:urlString]];

Try triggering reload of the table view when you are done with parsing. That is reload the table from the same method where you update your NSMutableDictionary.

Call [self.tableView reloadData];.

You have to tell the tableview to update. The tableview can't guess that your value has been updated ;)
Something like that should help
// Update your files normally...
// ...
// Trigger the reload
[self.tableView reloadData];

You can put ample debugging stuff into your table view controller class.
Here are some pointers:
When you call reloaddata, do you observe how many times tableView:cellForRowAtIndexPath get called? Do you get proper index values there?
Have you updated your tableView:numberOfRowsInSection: to reflect change in data source? ie the latest NSMutableDictionary count?
In your tableView:cellForRowAtIndexPath, put NSLog about NSMutableDictionary to see if it reflects the latest status?

I resolved the issue.
I changed my UiviewController superclass to UITableViewController. Thanks for your helps.

Related

UITableView does not repopulate with reloadData

I have a UITableView that successfully populates with a NSMutableArray. However, when I try to use a search function that I have implemented, the UITableView does not repopulate at all.
The NSMutableArray also contains the correct number of objects according to the search but when realoadData is called, the numberOfSections and numberOfRows methods are called, but the cellForRow method is not (even though the search returns 1 item). The delegate and datasource for the UITableView are correctly set up and connected using IB.
I am happy to paste some code, but I am unsure as to what relevant code would be helpful in discussion here.
Thanks
Answer: Just me being stupid and using a saved NSArray rather than the updated NSMutableArray to populate the table. Silly me...

When is tableView:numberOfRowsInSection: called in UITableView?

tableView:numberOfRowsInSection is sent to the delegate of a UITableView to find out how many rows it needs to have in a given section.
My question is, when and how often is this method called?
The method is called very first time the tableview is getting loaded and if you are more interested in the delegates then put a breakpoint and check when and where which delegate is called and how many times.
Below are the instances when that function will get called,
For the first time when table is loaded
the time you reload the table data
the time you add/update/delete your row or sections dynamically.
The method - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section is a protocol method of the UITableViewDataSource - protocol. It will be called
the very first time your table view is loaded based on that you have set the dataSource properly, e.g.
self.yourTableView.dataSource = self;
If you are interested in updating your table again at a later time you can call
[self.yourTableView reloadData];
in order to reload the entire table. If you are only interested in reloading a part of your table you can do something similar to
NSIndexSet *reloadSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [self numberOfSectionsInTableView:self.yourTableView])];
[self.yourTableView reloadSections:reloadSet withRowAnimation:UITableViewRowAnimationAutomatic];
Hope it helps!
My question is, when and how often is this method called?
Short Answer : When your UITableView needs to update something.
Long Answer : Delegates Methods generally called themselves however it may be called multiple times when your UITableView needs to update something. By default, it's called very first time the tableview is getting loaded or updated (reloaded).
It depends on how often user will scroll UITable view to section and how many sections there are. This value, which is returned by this function and is casched. Method will need be revoked if you will update content of table view (filtering results, or updating data via reloadData).
Best thing for you will be to add logging to this function and check this yourself.

Where to load my array?

- (void)viewWillAppear:(BOOL)animated
{
goals = [[NSArray alloc] init];
goals = [[self.operation valueForKeyPath:#"goal.goalNaam"] allObjects] ;
[self.tableView reloadData];
I'm loading my elements for my tableview in viewwillappear, as you can see in the code above. When the user adds something to the table (adding happens in a different view), it's added to Core Data and the array is loaded when the tableview is again appearing (after the dismissed "add-an-element-view"), now I want to delete something from the table. But the problem is that we're now staying in the same view (the tableview), so my array is not reloading (cause the viewwillappear is not executed). Anybody an idea how to solve this ?
You can call "[self viewWillAppear:YES];" after delete the data from Core data, So the datas are reloaded from the same view (Tableview)
You load your data in cellForRowAtIndexPath. This is called as cells come into view, and only cells in view (or almost in view) are loaded.
To force something to be reloaded, use reloadRowsAtIndexPaths or one of the other reload... methods.
Check out NSFetchedResultsControllerDelegate . You can set your VC as the fetch result delegate, and be notified when the data structure changes.

ASIHTTPRequest async updating uitableview

I'm using a UITableView which loads data from a server. I need to use async ASIHTTPRequest, which is in a separate .m.
How could I force to reload the table data when the requestFinished:request is called?
Thanks!
You can just send the data that needs to be loaded into the TableView by passing it between files. and then finally call a different method of inside the table view that implements the command [self.tableview relaodData];
Update:
What i see from your comments is that the you have a tableView CONtroller or someform of controller that loads the data by calling another class that holds the ASIHTTPrequest/ ansynchrinous requsts. now You have also told me that the TableView Also hold a UIViewController in each cell which i Dont think is a good idea you could go with a custom cell method have a look at this 4 part tutorial... now and the data that needs to be loaded into the TableView is loaded by TableViewController by some method wither it be each cell or something... so after you are able to get the data just inside the tableViewController just Call the [self.tablebview reloadData] inside the TableViewController which is the parent of the TableView there is no need to call in the other methods.
Finally solved with observers although when the app is completely closed won't work. I'll think in something.
Thanks

Populate UITableView with results of webservice

I have a table view which i want to populate with the results (XML) of my call to a web service.
The NSURLConnection and NSMutableURLRequest that are doing the setup for this are currently in my -viewDidLoad method, and i also have all of my UITableView delegate methods in my .m file too.
The data is being returned and added to my array correctly. My problem is (i think) that the UITableView methods are being called before any data has been returned from the web service, which is why my table view is always blank.
How can i call the methods in the right order (if this is even the problem)...
Are you calling reloadData on the tableview once you've repopulated the array? You need to let it know that you have new data.
UITABLEVIEW *mytableview=[[UITABLEVIEW alloc]init];
[mytableview reloadData];
Yes you are right; the UITABLEVIEW delegates are called before the web service. So you have to call those delegates again so try reloading the data. Works perfect for me. reload table when u have something returned from the webservice. store it in NSArray or whatever and then reload table.
Check out Apple's SeismicXML code example on the developer.apple.com/iphone site. It shows how to use NSURL, NSXMLParser, and a TableView to do just this type of thing.

Resources