2012-01-28 83 views
0

我想讓我的表格添加一個單元格在表格底部添加單元格,我的表格是在刪除模式下,所以人們可以刪除,但然後我需要它添加一個插入單元格的單元格,以插入單元格。我收到錯誤,說我的應用程序與nsarray不一致。我怎麼能做這個工作?您tableViewControllerUITableView addcell在編輯模式下底部

回答

1

第1步覆蓋setEditing插入或刪除添加行

- (void)setEditing:(BOOL)editing animated:(BOOL)animate 
{ 
    BOOL prevEditing = self.editing; 

    [super setEditing:editing animated:animate]; 
    [tableView setEditing:editing animated:animate]; 
    if (editing && !prevEditing) { 
     // started editing 
     [self.tableView insertRowsAtIndexPaths:....] withRowAnimation:UITableViewRowAnimationFade]; 
    } else if (!editing && prevEditing) { 
     // stopped editing 
     [self.tableView deleteRowsAtIndexPaths:....] withRowAnimation:UITableViewRowAnimationFade]; 

    } 


} 

然後確保你正在返回的行權數量

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    NSInteger numberOfRows = xxxxxx; 

    if (self.editing) { 
     numberOfRows++; 
    } 
    return numberOfRows; 
} 
相關問題