我的tableview中有5个部分1)1和2不可编辑而3,4和5是可编辑的 在上午1点使用复选框,2个单选框,3个插入单元格,4个删除单元格,5个移动单元格
所以对于最后3个我希望我的tableview可以编辑,并且+和 - 的符号将在单元格的开头显示。
而不是forst 2部分。 我试过 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
但这不起作用。有什么帮助吗?
答案 0 :(得分:5)
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
NSInteger section = [indexPath section];
if (section ==0)
return NO;
if (section ==1)
return NO;
if (section ==2)
return YES;
if (section ==3)
return YES;
if (section ==4)
return YES;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
[tableView reloadData];
}
答案 1 :(得分:0)
您与tableView:canEditRowAtIndexPath:
走在正确的轨道上。您还需要实施tableView:editingStyleForRowAtIndexPath:。
另外,您是否在UITableView上调用setEditing:animated以将表格置于编辑模式?我猜你是,但是仔细检查就不会受到伤害。