在编辑模式下使用不同的tableview单元格

时间:2014-12-08 17:53:24

标签: ios uitableview swift

我想在“通讯录”应用中做类似的事情:

标准模式有一些单元格 enter image description here  和其他编辑模式。 enter image description here 我试过的是:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    if self.editing{
        let cell = tableView.dequeueReusableCellWithIdentifier(TextFieldCellIdentifier, forIndexPath: indexPath) as TextFieldTableViewCell
        return cell
    }else{
        let cell = tableView.dequeueReusableCellWithIdentifier(ButtonCellIdentifier, forIndexPath: indexPath) as ButtonTableViewCell
        return cell
    }
}

我应该在何处以及如何触发重新加载的单元格?

1 个答案:

答案 0 :(得分:2)

听起来您希望在用户进入或离开编辑模式时,表格视图单元格可以重新加载到单元格的相应编辑/非编辑版本。如果我理解正确,那么你可以为编辑属性提供一个setter,以便在编辑模式改变时重新加载表视图单元格。

override func setEditing(editing: Bool, animated: Bool) {
    tableView.reloadData()

    self.tableView.beginUpdates()
    super.setEditing(editing, animated: animated)
    self.tableView.endUpdates() 
}