简体   繁体   中英

Don't have delete button when swipe on table row

I create new project, Then add TableView to ViewController, set dataSource and delegate to View Controller, Add one prototype cell with Basic style and identifier "cell". My ViewController.swift class:

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)
        }
    }

}

When I swipe row, it moving but delete button is missing. Where I am wrong?

Just replicated your project. Delete button is there.

在此处输入图片说明

You should check the constraints of your table view to make sure it does not inadvertently extend beyond the right edge of the screen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM