【发布时间】:2015-01-07 11:01:43
【问题描述】:
我正在尝试通过单击单元格来模拟单元格的拖动。
点击后,单个单元格必须是列表中的第一项。 我尝试了该方法,但我的索引路径发生了变化,但我没有在表中看到结果,即使我重新加载它也是如此。
有什么建议吗?
这是我的代码:
import UIKit
var array = ["1", "2", "3", "4", "5", "6"]
class Table: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.setEditing(true, animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel.text = array[indexPath.row]
return cell
}
var indexPathForCell = NSIndexPath(forRow: 0, inSection: 0)
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPathForCell: NSIndexPath) {
tableView.reloadData()
println(indexPathForCell)
//
}
override func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath indexPathForCell: NSIndexPath) {
println(indexPathForCell)
}
}
谢谢
【问题讨论】:
-
我不太明白你想要完成什么。你想让你点击的任何单元格移到列表顶部吗?
-
是的!正是这一点,但动画也是如此。谢谢你的回复
标签: sorting swift tableview cell