开发者

uiTableView problem - xcode

i'm new to xcode and i'm trying to learn. I have followed this tutorial http://p2p.wrox.com/content/articles/creating-simple-ipad-application-table-view on displaying a UITableView within an iPad and i have one questions :

  1. Is it possible to update the tableview during runtime? For example, I would like t开发者_C百科o have two button and when i press them, one would erase the content and the other would add content?


Yep you can. You can use the following methods on the UITableView:

  • insertRowsAtIndexPaths:withRowAnimation:
  • deleteRowsAtIndexPaths:withRowAnimation:
  • insertSections:withRowAnimation:
  • deleteSections:withRowAnimation:

Wrap those calls in a beginUpdates & endUpdates to ensure that the animations are done in a block.

Note:

UITableView calls the relevant delegate and data source methods immediately afterwards to get the cells and other content for visible cells.

So you need to make sure your data source reflects your newly inserted/deleted rows. Have a look at Batch Insertion, Deletion, and Reloading of Rows and Sections for more information.

Deleting Rows

I thought it was worth noting that a better way to delete rows from your table (based on user input) would be to implement the tableView:commitEditingStyle:forRowAtIndexPath: method on your UITableViewDataSource. If you implement this method then the swipe to delete functionality will be available on your table view.


Yes, just empty your array and reload the table..

[array RemoveAllObjects];
[table reloadData];

and if you want to add content, add content to the array and reload the table using:

[array addObject:newdata];
[table reloadData];


for updating your table view you can call reloadData after updating your data source for example if you are using an array then first update your array and then call reloadData.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜