且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我在尝试删除tableview ios中的部分时出现断言错误

更新时间:2023-02-06 23:40:20

我发现了一个修复,但我避免使用sectionFooter,因为这似乎有问题。

I found a "fix", but I'm avoiding the use of sectionFooter, because that seems to be bugged.

我在每个部分的末尾创建了一个额外的单元格,使用了我之前为我的页脚View设置的相同设置,并使最后一个单元格不可编辑

I created an extra cell at the end of each section, with the same setup I had for my footer View before, and made that last cell not editable with

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    TableSection * sec = [self.sections objectAtIndex:indexPath.section];
    if (sec.items.count != indexPath.row) {
        return YES;
    } else
        return NO;
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

        return [sec.items count] +1 ;

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"normalcell";
static NSString *CellIdentifier1 = @"footercell";


TableSection * sec = [self.sections objectAtIndex:indexPath.section];

if (indexPath.row != sec.items.count) {
    //use normal type of cell


    return cell;
} else{
    //use footer type of cell

    return cell;
}

}

所以最后一个单元格模仿页脚,但它没有粘在框架的底部,但我将不得不忍受。它比崩溃更好。

So the last cell Imitates a "footer", but it's not stuck to the bottom of the frame, but I'll have to live with that. It's better than crashes.