【发布时间】:2021-08-02 10:03:41
【问题描述】:
我使用带有可编辑自定义样式单元格的表格视图。导航栏中有一个Edit 按钮,用于切换编辑模式。我需要编辑模式来删除和重新排序行。
当我向左滑动单元格时,Delete 操作按钮会显示在该单元格的右侧。当它显示时,我按下Edit 按钮,Delete 操作按钮消失。再次按下Edit 按钮会显示左侧的删除命令和右侧的所有(!)单元格的重新排序控件。到目前为止一切都符合预期。
现在(例如),当我向左滑动单元格 0,然后向左滑动单元格 1 时,单元格 0 中的 Delete 操作按钮仍然可见,使用 Edit 按钮激活编辑模式现在会向左显示删除命令并重新排序所有单元格的控制权,除了(!)单元格 0。
我发现,只要 2 个或更多单元格被左擦除,第一个未右滑退出编辑模式的单元格,在使用启用所有单元格的编辑模式时会错过删除控件(左) Edit 按钮。更奇怪的是……在主题单元格缺少删除控件(左)上,重新排序控件(右)正确显示!
我关注并比较了许多教程,但没有发现错误。
我错过了什么?
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
...
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
...
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
...
}
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
...
}
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
...
}
override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
...
}
// not necessary = didn't change anything, but found in many tutorials
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
}
@IBAction func editAction(_ sender: Any) { // that's the Edit button action
self.setEditing(!isEditing, animated: true)
self.navigationItem.leftBarButtonItem?.title = isEditing ? "Done" : "Edit"
}
在所有涉及的方法之上。不相关的方法内容被省略以保持帖子紧凑。如果认为需要,我会添加/编辑。
【问题讨论】:
-
能否请您发布一些带有错误的屏幕截图,否则很难想象发生了什么。
标签: swift uitableview uitableviewrowaction