【问题标题】:Don't have delete button when swipe on table row在表格行上滑动时没有删除按钮
【发布时间】:2014-11-09 10:13:56
【问题描述】:

我创建新项目, 然后将TableView添加到ViewController,设置dataSource和delegate给ViewController, 添加一个具有基本样式和标识符“单元格”的原型单元格。 我的 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)
        }
    }

}

当我滑动行时,它移动但删除按钮不见了。 我哪里错了?

【问题讨论】:

    标签: ios swift


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-10-24
      • 2017-06-23
      • 1970-01-01
      • 2011-03-19
      • 1970-01-01
      • 1970-01-01
      • 2012-07-18
      • 2012-08-01
      相关资源
      最近更新 更多