How to reload a table view in a view controller in iphone?
-
25-09-2019 - |
Question
I am new to iphone development.I have created a table view in a view controller. I want to reload the table view so that i can display the contents which are parsed previously in delegates. More over reloadData
does only reload the cells. It doesn't take care of actually updating the underlying datasource.
E.g. if i read data from an array in tableView:cellForRowAtIndexPath:, I have to change the array values befor calling reloadData.
How can i achieve this. Please help me out.Thanks.
Solution
It sounds like you need a manager class (or something) to encapsulate the process of requesting, downloading, parsing the data and updating your model objects.
You can use delegation to tell the view controller to reload after you've done all of the above.
OTHER TIPS
If you have a delegate method that returns you the values that that needs to be refreshed in the TableView do the following:
- (void)didFetchData:(NSArray*)dataList
{
//Update the dataSource List that is used in the tableView
self.dataSourceList = [NSArray arrayWithArray:dataList];
//Now call the reload method to update the data.
[self.tableView reloadData];
}
Note: Always make sure you update the dataSource object and then call the [tableView reloadData]