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

标签 ios swift

我创建新项目, 然后将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)
        }
    }

}

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

最佳答案

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

enter image description here

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

关于ios - 在表格行上滑动时没有删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26827122/

相关文章:

android - 如何将图像添加到推送通知?

ios - 我可以在 Apple Wallet 中访问哪些通行证

swift - 快速显示来自共享类的警报

ios - swift5 中更新和删除钥匙串(keychain)时出现问题

ios - prepareForSegue 错误 ""在展开可选值时意外发现 nil""

TableView 单元格中的 iOS 布局约束冲突

ios - UITableView 索引路径行为奇怪

ios - UILabel更新时,UIImageView消失

ios - 使用不同单位类型进行测量的最佳方法

ios - 单击单元格中的按钮时如何解析以播放某首歌曲?