UITableView addcell在编辑模式下底部

问题描述:

我想让我的表格添加一个单元格在表格底部添加单元格,我的表格是在删除模式下,所以人们可以删除,但然后我需要它添加一个插入单元格的单元格,以插入单元格。我收到错误,说我的应用程序与nsarray不一致。我怎么能做这个工作?您tableViewControllerUITableView addcell在编辑模式下底部

第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; 
}