【问题标题】:iOS Swift: UITableViewCell editing set true after row deletioniOS Swift:删除行后 UITableViewCell 编辑设置为真
【发布时间】:2015-03-08 21:45:44
【问题描述】:

删除 UITableView 中的一行后,我创建的下一行的编辑设置为 true。我不确定这是为什么,但这意味着在我删除一行之后,我创建的下一行是indented on the left side by about 40 points

删除单元格后是否需要将表格或单元格设置为editing = false

func removeItems(items: [CKRecord], indexPath: NSIndexPath) {
    for item in items {
        db.deleteRecordWithID(item.recordID) { (record, error) -> Void in
            if error != nil {
                println(error.localizedDescription)
            }

            dispatch_async(dispatch_get_main_queue()) { () -> Void in
                if let index = find(exercises, item) {
                    exercises.removeAtIndex(index)
                }
            }
        }
    }

    days.removeAtIndex(indexPath.row)
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}

【问题讨论】:

  • cell.editing = false 添加到cellForRowAtIndexPath 解决了这个问题,但似乎很笨重。

标签: ios swift uikit


【解决方案1】:

显然,删除一行并不会禁用对该行的编辑。我在deleteRowsAtIndexPaths 之前添加了这一行,这似乎可以解决问题:

tableView.cellForRowAtIndexPath(indexPath)?.setEditing(false, animated: false)

我的理解是,当我在一个单元格上滑动时,我正在启用对该单元格的编辑。而且因为我插入的下一个单元格位于相同的索引处,所以它是在启用编辑的情况下绘制的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-29
    相关资源
    最近更新 更多