从Swift 1.2更新tableView代码 - 2.0

时间:2015-09-18 13:26:16

标签: xcode swift swift2 ios9

我编写了这段代码来编辑行样式(Swift 1.2 - Xcode 6.4)

func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle
{


    let edit = UITableViewRowAction(style: .Normal, title: "Edit") { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in

        let abb: AnyObject = self.frc.objectAtIndexPath(indexPath)
        let editingView = self.storyboard?.instantiateViewControllerWithIdentifier("editingViewController") as! editingViewController
        editingView.abbediting = abb
        self.presentViewController(editingView, animated: true, completion: nil)
        print("Edit Tapped")

        print("Edited Button Clicked")  }
    edit.backgroundColor = UIColor.lightGrayColor()

    let delete = UITableViewRowAction(style: .Normal, title: "Delete") { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in

        let abbDel = self.frc.objectAtIndexPath(indexPath) as! NSManagedObject
        self.con?.deleteObject(abbDel)



        print("Delete Button Clicked")
    }
    delete.backgroundColor = UIColor.redColor()


   return [delete,edit]


}

我还设置了一些操作,但是在我更新到Xcode 7.0和Swift 2.0之后,我收到错误告诉我返回UITableViewCellStyle。

任何正文都可以帮助我将代码更新为适合使用Swift 2.0的内容吗?

1 个答案:

答案 0 :(得分:0)

我认为您的代码属于editActionsForRowAtIndexPatheditingStyleForRowAtIndexPath需要返回该行的编辑样式,例如UITableViewCellEditingStyle.Delete。点击“编辑”按钮时显示的样式。