无法移动表格视图单元格时删除
问题描述:
我有一个表视图与所有必需的数据源和委托方法。无法移动表格视图单元格时删除
当我滑动单元格时正在运行,删除按钮出现,但出现在单元格内容中。 单元格不移位。
我预计移动细胞的功能出现在下面的代码,但它不会
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row)
return YES;
else
return NO;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[[NoteManager sharedManager] removeNoteAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
请帮我解决这个简单的问题 快速的帮助是appriciated ..
答
将子视图添加到单元格时,请确保将它们添加到单元格的contentView
,而不是单元格。
[cell.contentView addSubview:someSubview];
contentView
的框架将根据需要进行调整,包括删除按钮在内的各种单元装饰。