UITableView在编辑模式下将addcell添加到底部

时间:2012-01-28 08:30:04

标签: uitableview nsarray

我正在尝试让我的表在表格的底部添加一个单元格来添加单元格,我的表格处于删除模式,所以人们可以删除,但之后我需要它添加一个带插入的单元格插入一个单元格。我收到错误,说我的应用程序与nsarray不一致。我怎么能做这个工作?

1 个答案:

答案 0 :(得分:1)

步骤1覆盖tableViewController上的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;
}