ios - 无法对 tableView 使用 moveRowAtIndexPath
问题描述
目前我在我的自定义表格视图中显示一个简单的对象数组,我还使用SwipyCell来测试滑动手势。
然后我尝试使用重新排序对象,moveRowAtIndexPath
但是由于某种原因它不适用于以下代码。
func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
let itemThatMoved = self.tasks[sourceIndexPath.row]
self.array.remove(at: sourceIndexPath.row)
self.array.insert(itemThatMoved, at: destinationIndexPath.row)
// Change data properties
}
func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the item to be re-orderable.
return true
}
我还在 ViewController 中设置了以下内容
table.isUserInteractionEnabled = true
table.allowsSelectionDuringEditing = true
table.allowsSelection = true
有没有人有任何建议我可能做错了什么?
解决方案
如果您使用的是 Swift 3+,则委托方法的签名是错误的
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool
和
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)
推荐阅读
- javascript - 如何在 html 页面中翻译 Javascript 消息
- python - 从字符串构造快速布尔逻辑
- firebase - 在本机反应中基于互联网连接运行功能
- xamarin.android - Xamarin.Android CertificateFactory.GetInstance("X.509").GenerateCertificate with MemoryStream 结果为“inStream 为空”
- multithreading - 使用信号量保持和等待
- sql - 循环两次同一张表
- .net - 从不同的线程 VB.net 在主线程上打开表单
- certificate - 更新到 VSCode 1,56.1,现在从我的扩展程序中获取 REST 调用的证书错误。V 1.55.2 工作正常
- php - 在 json 中列出具有最新提交 id 的 git 分支
- c# - 悬停在游戏对象统一时如何显示文本