Swift:UITableView setEditing使UITextField移动

时间:2018-07-02 19:22:57

标签: ios swift uitableview

我在UITableViewCell中有2个UITextField。调用setEditing时,我还要更改borderStyle并启用TextFields。

进入编辑模式时,在动画过程中,UITextField中的文本会跳到左侧,然后再移回到右侧。退出编辑模式后,它会跳到UILabel旁边的UITextField上方。

这是单元格setEditing的内容:

    super.setEditing(editing, animated: animated)

    self.name.isEnabled = editing
    self.value.isEnabled = editing

    if !editing {
        self.name.borderStyle = .none
        self.value.borderStyle = .none
    }
    else {
        self.name.borderStyle = .roundedRect
        self.value.borderStyle = .roundedRect
    }

这是editActionsForRowAt

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
        _ = self.list.removeItem(at: indexPath.row)
        tableView.deleteRows(at: [indexPath], with: .fade)
    }

    return [delete]
}

即使我删除了动画,这些字段也发生了奇怪的事情。

Here是活动单元的视频

编辑:这似乎是UITextField中的文本右对齐的副作用。

0 个答案:

没有答案