【发布时间】:2017-04-25 06:19:20
【问题描述】:
我想在使用表格编辑模式时防止表格单元格的内容向左侧移动。我在视图控制器中实现了以下UITableViewDelegate 方法:
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
如建议:
Prevent indentation of UITableViewCell (contentView) while editing
但它似乎从未被调用过。这也不起作用:
cell.shouldIndentWhileEditing = NO;
我正在使用几个自定义编辑行操作,它们的定义如下:
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView
editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableArray<UITableViewRowAction *> *actions = [NSMutableArray array];
id clearHandler = ^(UITableViewRowAction *action, NSIndexPath *indexPath) {
...
};
UITableViewRowAction *clearAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDestructive
title:@"Clear\nStatus"
handler:clearHandler];
[actions addObject:clearAction];
id editHandler = ^(UITableViewRowAction *action, NSIndexPath *indexPath) {
...
};
UITableViewRowAction *editAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleNormal
title:@"Edit"
handler:editHandler];
[actions addObject:editAction];
return actions;
}
我仔细检查了表格视图的delegate 属性是否指向视图控制器。我还缺少什么?
表格视图样式未分组,即普通。
【问题讨论】:
-
您使用的是分组表视图吗?来自
UITableView.h:“此方法仅适用于分组样式表视图。” -
你的问题解决了吗?
-
@norders 表格样式很简单。那么对于普通的表格视图来说不可能实现这一点?
-
我不知道,但请尝试将表格样式切换为“分组”。如果它有效,那么我会说'不';-)
-
尝试使用自定义 UITableViewCell 并使用 xib 文件设置单元格中项目的位置。
标签: ios objective-c uitableview