开发者

Reloading a tableview with completely new data, and an animation in between

开发者 https://www.devze.com 2023-04-03 05:02 出处:网络
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 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:

  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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消