【发布时间】:2014-08-09 20:43:17
【问题描述】:
当我将 UITableView 置于编辑模式时,我一直试图阻止 (-) 删除指示符出现。
为清晰起见更新:
这是表格的样子:
这是我在 - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
当我点击重新排序时,我会进入编辑模式。我不希望这些显示:
我通过将editActionsForRowAtIndexPath 中显示的按钮限制为仅删除来解决第三个屏幕截图,但我什至不想进入这部分。我希望编辑模式仅重新排序
/更新
我试过设置 UITableViewCell.shouldIndentWhileEditing = NO
直接在单元格上:
cell.indentationLevel = -3;
cell.shouldIndentWhileEditing = NO;
在界面生成器中
在适当的委托方法中
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"shouldIndentWhileEditingRowAtIndexPath");
return NO;
}
我还显示了操作列表中的项目。我根本没有计划在编辑模式下删除,只是重新编码。我已经调整了一些东西,所以我只在用户滑动时显示删除,但我宁愿 (-) 根本不显示:
- (void) endEditing
{
self.editMode = NO;
self.editControlButton.title = @"Reorder";
[self setEditing:NO animated:YES];
//[self.tableView reloadData];
}
- (void) startEditing
{
self.editMode = YES;
self.editControlButton.title = @"Done";
[self.tableView setEditing:YES animated:YES];
}
#pragma - mark UITableViewDelegate
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"shouldIndentWhileEditingRowAtIndexPath");
return NO;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
TCORead *item = [self.fetchedResultsControllerDataSource selectedItem];
manager.currentRead = item;
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView setEditing:NO];
}];
//workaround, rdar://17969970
//normally don't want to be able to get into this menu when reordering
if (!self.editMode) {
UITableViewRowAction *shareAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Share" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView setEditing:NO];
}];
shareAction.backgroundColor = [UIColor grayColor];
UITableViewRowAction *doneAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Done" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView setEditing:NO];
}];
doneAction.backgroundColor = [UIColor greenColor];
[self startEditing];
return @[deleteAction, doneAction, shareAction];
}
return @[deleteAction];
}
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
[self endEditing];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
//empty on purpose
}
【问题讨论】:
-
当 tableView 进入编辑模式时,你到底想发生什么?如果不想出现删除按钮,为什么还要使用编辑模式?
-
@Dan 谢谢,我已经用截图更新了这个问题。我正在使用编辑模式来允许重新排序。但是,可以处理编辑模式之外的删除
标签: ios objective-c uitableview