2011-04-19 67 views
1

我需要在表中添加'ADD NEW ROW'單元格。我添加它,但我有問題完成它。在這個'setEditing'方法中,我不知道我需要在'paths'數組中放置什麼?在UITableView中插入一行 - 缺少一些東西

-(void)setEditing:(BOOL)editing animated:(BOOL)animated { 
    [super setEditing:editing animated:animated]; 
    [self.tableView setEditing:editing animated:animated]; 
    //[self.tableView reloadData]; 

    NSMutableArray* paths = [[NSMutableArray alloc] init]; 

    // fill paths of insertion rows here 

    if(editing) 
     [self.tableView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationBottom]; 
    else 
     [self.tableView deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationBottom]; 

    [paths release]; 
} 

回答

2

您必須在此路徑數組中添加indexPath對象。您可以創建NSIndexPath實例爲 -

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0]; 
+0

是的saadnib是正確的。當你這樣做後,table將要求在tableView中添加一行:rowForIndexPath:這是你應該返回新的單元格對象的地方 – 2011-04-19 11:25:03

+0

謝謝,就是這樣。但在結束問題之前還有一件事。當我按下添加按鈕代碼進入'commitEditingStyle'方法。但我不明白。沒有要求我爲我的表輸入新的項目名稱? – 1110 2011-04-19 11:41:16

+0

好的,我會添加新的視圖添加圖標點擊添加項目。我會將其作爲模態視圖。 – 1110 2011-04-19 11:46:10