I have a view (.xib) which consists of a tableview assigned to an array. Using the method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
I tell the table to do a animation once a cell is selected, my question is how do I assign the table a completely new array to use for its dat开发者_如何学编程aSource, and reloadData before the animation occurs.
You have to do the following:
- within
didSelectRowAtIndexPath
you have to make sure that your new table data is beeing set. That means that calling the UITableView access methods like:numberOfSectionsInTableView, cellForRowAtIndexPath, ....
all will return now your new and correct values for the new table - then just do a
[theTableView reloadData];
- Additionally I like to suggest that handling the cell you just pressed on is taken care of nicely, eg deselect it or whatever you like
When you call reloadData(), it will call the delegate method and change the table's cells to whatever array you bound to it. So all you need to do is change your array to hold the data for the new table's cells, then call reloadData() and your table will refresh and contain your new data.
If you are trying to create a hierarchy of table views, I recommend you use a navigationController to manage your table views. Hope this helps.
精彩评论