0
votes

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 dataSource, and reloadData before the animation occurs.

2

2 Answers

0
votes

You have to do the following:

  1. 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
  2. then just do a [theTableView reloadData];
  3. 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
0
votes

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.