我创建新项目, 然后将TableView添加到ViewController,设置dataSource并委托(delegate)给View Controller, 添加一个具有基本样式和标识符“cell”的原型(prototype)单元格。 我的 ViewController.swift 类:
class ViewController: UIViewController, UITableViewDelegate{
var numbers = ["One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return numbers.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cell") as? UITableViewCell
cell?.textLabel.text = numbers[indexPath.row]
return cell!
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete {
numbers.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
}
当我滑动行时,它移动但删除按钮丢失了。 我哪里错了?
最佳答案
刚刚复制了您的项目。删除按钮在那里。
您应该检查 TableView 的约束,以确保它不会无意中超出屏幕的右边缘。
关于ios - 在表格行上滑动时没有删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26827122/