我知道以前已经有人问过这个问题,但通常的修复(实现委托(delegate)和数据源方法、适当设置委托(delegate)和数据源等)不起作用。我完全被难住了。
尽管设置了委托(delegate)和数据源,将 tableView 设置为编辑,告诉单元格显示重新排序控件并实现了所需的方法,但重新排序控件将不会显示。 tableView 进入编辑模式,因为我可以看到删除控件。但重新排序控件从未显示,我无法对单元格重新排序。
我什至删除了所有自定义单元格加载和自定义,以防出现问题。我只是不知道出了什么问题。奇怪的是, tableView:canMoveRowAtIndexPath:
似乎没有被调用,因为日志从未出现在控制台中。
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame style:UITableViewStyleGrouped];
if (self) {
self.delegate = self;
self.dataSource = self;
self.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1.0];
self.separatorInset = UIEdgeInsetsZero;
self.delaysContentTouches = NO;
[self loadImagePicker];
[self registerClass:[ExpandingTitleTableViewCell class] forCellReuseIdentifier:[ExpandingTitleTableViewCell reuseIdentifier]];
[self registerClass:[SliderTableViewCell class] forCellReuseIdentifier:[SliderTableViewCell reuseIdentifier]];
[self registerClass:[UndoRedoTableViewCell class] forCellReuseIdentifier:[UndoRedoTableViewCell reuseIdentifier]];
[self registerClass:[NudgeImageTableViewCell class] forCellReuseIdentifier:[NudgeImageTableViewCell reuseIdentifier]];
self.alwaysBounceVertical = NO;
self.editing = YES;
}
return self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *reuseIdentifier = nil;
Class cellClass = nil;
//Custom cell class setting code was here
reuseIdentifier = @"Cell";
cellClass = [UITableViewCell class];
//Cell customisation code was here
cell.showsReorderControl = YES;
return cell;
}
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath {
//TBC
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Can move row");
return YES;
}
最佳答案
嗯,明白了。我重写了错误的方法。我覆盖了 moveRowAtIndexPath:toIndexPath:
,而不是 tableView:moveRowAtIndexPath:toIndexPath:
。第一个可能是 UITableView 上实际移动行的方法。它出现在自动完成中,因为这个 tableView 是它自己的委托(delegate)和数据源。我已经实现了正确的方法并且现在可以工作了。
关于ios - UITableView 不会显示重新排序控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48843116/