ios - UITableView 不会显示重新排序控件

标签 ios uitableview

我知道以前已经有人问过这个问题,但通常的修复(实现委托(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/

相关文章:

ios - 无法在 Swift 中的 TableView 的另一个 View Controller 中显示值

ios - UITableView 仅加载设备上可见的自定义单元格,并在添加一个单元格时崩溃

ios - NSOperationQueue : currentQueue/new?之间的区别

ios - 针对特定 UITableViewCell 中的特定 UILabel

java - 等效于 Objective C/Swift 的 Java ThreadLocal 变量

ios - 如何在 Swift 中使用 htonl 设置整数字节顺序?

ios - UITableView 和 UITextField borderColor 问题

iphone - 如何从分组部分 uitableview 添加/删除单元格?

ios - 另一个 VC 中的 VC 没有按下按钮(移动到 XCode8 后)

ios - 按下时提供相同细节的多个注释