【发布时间】:2013-12-20 07:25:06
【问题描述】:
我有一个包含自定义单元格的动态 tableView,例如,如果它的值为 0,我想删除一些单元格。
这是我的tableView:cellForRowAtIndexPath 方法:
{
NSString *CellIdentifier;
UITableViewCell *cell;
if (indexPath.row == 0){
CellIdentifier = @"adress cell";
CustomAdressCell *cell = [detailsTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CustomTimeCell" owner:self options:nil];
cell = [objects lastObject];
}
cell.someValue = self.someVal;
return cell;
}
else if (indexPath.row == 1){
CellIdentifier = @"phone cell";
CustomPhoneCell *cell = [detailsTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CustomPhoneCell" owner:self options:nil];
cell = [objects lastObject];
}
indexPathTest = indexPath;//index path for delete
cell.someValue = self.someVal2;
return cell;
}
...
else return cell;
}
例如:如果我在第二行有cell.someValue = 0,我需要删除这一行。我怎样才能做到这一点?谢谢!
编辑:在使用以下代码(自定义方法)在另一个 VC 中初始化我的 tableView 后,我试图删除行:
[self.detailsTableView beginUpdates];
[self.detailsTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPathTest]
withRowAnimation:UITableViewRowAnimationFade];
[self.detailsTableView endUpdates];
我有错误:
Invalid update: invalid number of rows in section 0. The number of rows contained in an
existing section after the update (4) must be equal to the number of rows contained in that
section before the update (4), plus or minus the number of rows inserted or deleted from that
section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that
section (0 moved in, 0 moved out).'
其他一些对我没有帮助的问题:
【问题讨论】:
标签: ios iphone objective-c uitableview