【发布时间】:2010-05-29 11:13:58
【问题描述】:
我有一个表格视图并希望允许对所有单元格重新排序,但是我不希望允许删除某些单元格。当 UiTableView 进入删除模式时,我不希望红色的“-”按钮出现在左侧,也不希望滑动手势调出这些单元格的删除按钮,但希望它发生在其他单元格上.有任何想法吗?
【问题讨论】:
标签: ios iphone uitableview cocoa-touch
我有一个表格视图并希望允许对所有单元格重新排序,但是我不希望允许删除某些单元格。当 UiTableView 进入删除模式时,我不希望红色的“-”按钮出现在左侧,也不希望滑动手势调出这些单元格的删除按钮,但希望它发生在其他单元格上.有任何想法吗?
【问题讨论】:
标签: ios iphone uitableview cocoa-touch
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
//if we cant delete the object represented at the index path
if ([[tableViewObjectsArray objectAtIndex:indexPath.row] canBeDeleted] == NO){
return UITableViewCellEditingStyleNone;
}
//otherwise allow the deletion
else{
return UITableViewCellEditingStyleDelete;
}
}
当然,这会在“-”按钮所在的位置留下一个空白区域,但不允许删除。而且也不允许滑动删除。
【讨论】:
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath 以防止缩进,如果你不想这样做:)
实现:
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
【讨论】: