在表格行上滑动时没有删除按钮

时间:2014-11-09 10:13:57

标签: ios swift

我创建了新项目, 然后将TableView添加到ViewController,将dataSource和委托添加到View Controller, 添加一个具有Basic样式和标识符“cell”的原型单元格。 我的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)
        }
    }

}

当我向上滑动行时,它会移动,但缺少删除按钮。 哪里错了?

1 个答案:

答案 0 :(得分:2)

刚刚复制了你的项目。删除按钮就在那里。

enter image description here

您应该检查表视图的约束,以确保它不会无意中延伸到屏幕的右边缘。