【发布时间】:2018-10-25 15:16:31
【问题描述】:
目前我在我的自定义表格视图中显示一个简单的对象数组,我还使用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 2 吗?如果是,我们鼓励您更新。如果 no 代表方法的签名是错误的。
-
@vadian 你能详细说明一下吗?不,它不应该是 Swift 2
-
你是如何添加这两个委托方法的?您是否从一些示例代码中复制和粘贴?不要复制旧代码,也不要自己输入。让 Xcode 为你输入大部分内容。
标签: ios arrays swift tableview