ios - UITableView - 在编辑模式下重复使用单元格

标签 ios uitableview

我发现,如果您将表格 View 设置为编辑模式,则在删除一行后滚动表格时,单元格编辑控件(左侧的红色减号)处于随机状态(垂直或水平)滚动表格时在其余单元格上。大概是因为我正在重用这样的单元格:

cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

如何强制每个单元格的编辑控件处于正确状态?它应该始终处于默认水平状态,除非我点击它来删除单元格。

编辑:这是单元格代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"WhateverIdentifier";
    MyCell *cell = nil;

    //This IF statement fixes the problem, but then I'm not reusing the cells
    if (!tableView.isEditing) {
        cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    }

    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil] objectAtIndex:0];

    }

    //customize cell

    return cell;
}

最佳答案

您是否在自定义单元格的 prepareForReuse 方法中调用了 [super prepareForReuse]

这解决了我的问题。

关于ios - UITableView - 在编辑模式下重复使用单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17200540/

相关文章:

swift - 滚动时调整 UITableViewCell 图像的大小

ios - 在页 footer 分创建按钮并检测正确的点击

ios - 如何使用动画以编程方式隐藏和显示 WKInterfaceGroup?

ios - 如何找出导致我的 iOS 应用程序崩溃的原因(EXC_BREAKPOINT)?

ios - 重新启动场景时崩溃

ios - Segues 直接从 Storyboard xcode 中的 View Controller 警告启动

objective-c - 使用 ARC 延迟释放包含的对象?

ios - UITableView 在 Swift 中总是显示基本单元而不是自定义单元

ios - swift 从领域数据库中获取所选 TableView 行的主键

ios - 当单元格移出屏幕时如何停止单元格中的 AVPlayer 播放