2012-10-10 24 views
0

我想從另一個類訪問tableView屬性(在UITableViewController類中定義)。一旦我訪問它,我需要發送它的方法如何從不同的類中將新行插入到tableview中?

insertRowsAtIndexPaths: withRowAnimation:UITableViewRowAnimationAutomatic: 

這是我的代碼,但它似乎不插入新行?

[((MainViewController *)self.presentingViewController).tableView insertRowsAtIndexPaths:@ [路徑] withRowAnimation:UITableViewRowAnimationAutomatic];

回答

0

你需要確保你的數據源也修改自己。所以,如果你插入新行,你需要

-tableView:numberOfRowsInSection:

返回比以前多1和

-tableView:的cellForRowAtIndexPath:

返回新電池。 TableView不會爲你處理這些部件。

下面是你的代碼應該看起來像一個粗略的輪廓。

[tableView beginUpdates]; 
// Some code to add row to your datasource 
[datasource addrow] 
[tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic]; 
[tableView endUpdates]; 
+0

我設法弄明白了,但是無論如何感謝 – user1628311

相關問題