ios - 在 UITableView 中默认启用重新排序控件而不处于编辑模式
问题描述
我目前正在研究一种解决方案,在该解决方案中,我需要UITableView
默认情况下在重新排序模式下没有删除按钮,但可以在必要时启用删除按钮。我只是好奇这是否可以在 iOS 中实现?如果是这样,我的方法应该是什么?
解决方案
在我看来,您的表格视图应该始终处于编辑模式。
要使重新排序控件出现,您应该实现 UITableViewDataSource 方法
tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool
和
tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)
如果您不希望显示删除按钮,您可以通过实现
tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle
并在默认情况下返回 .none 或在您想要显示按钮时返回 .delete 。
推荐阅读
- oracle - 即使没有匹配的记录,函数也会返回 1
- verilog - 如何从 TSMC 65nm 标准单元库生成 .db 文件?
- xamarin.forms - 使用数据绑定设置一个简单的组件
- kotlin - 迭代器函数不适用于内部变量
- git - 尝试将 GIT 克隆到我的 Windows 10 电脑时出现错误
- c# - EF:同一父表上的多个 1 对 1 或零
- php - Timeago 给了我错误的时间
- python - 在带有 bs4 的 python 中使用正则表达式从脚本中抓取电子邮件地址
- intellij-idea - 我可以使用 IntelliJ Idea-community 版本调试注释处理器吗?
- javascript - 不能在js函数中使用jquery依赖库