editActionsForRowAtIndexPath不起作用

时间:2016-01-20 19:14:13

标签: ios swift uitableview

我正在使用Swift开发一个小应用程序,一个UITableView来显示自定义单元格,然后我想滑动编辑来执行此操作我使用以下代码:

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! BasicCell
        cell.Name.text = contacts[indexPath.row].Name
        cell.Phone.text = contacts[indexPath.row].Phone
        cell.ProfilPic.load(contacts[indexPath.row].ProfilPic!)
        cell.ProfilPic.layer.masksToBounds = true
        cell.ProfilPic.layer.cornerRadius = CGRectGetWidth(cell.ProfilPic.frame)/2.0




        return cell
    }



    func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) ->  [UITableViewRowAction]?{
        let delete = UITableViewRowAction(style: .Normal, title: "Delete") { action, index in
            print("delete")
        }
        let done = UITableViewRowAction(style: .Default, title: "Done") { action, index in
            print("done")
        }
        return [delete, done]
    }

    func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // the cells you would like the actions to appear needs to be editable
        return true
    }

    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        // you need to implement this method too or you can't swipe to display the actions
    }

问题是当我刷一个单元格时,按钮没有显示:

enter image description here

0 个答案:

没有答案