2

In my app I have class defined as follows:

class MyTableViewController: UITableViewController {

and inside I wanted to add the functionality of swiping selected cells (taken from this answer)

But when I write there this:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
    let more = UITableViewRowAction(style: .Normal, title: "More") { action, index in
        print("more button tapped")
    }
    more.backgroundColor = UIColor.lightGrayColor()

    let favorite = UITableViewRowAction(style: .Normal, title: "Favorite") { action, index in
        print("favorite button tapped")
    }
    favorite.backgroundColor = UIColor.orangeColor()

    let share = UITableViewRowAction(style: .Normal, title: "Share") { action, index in
        print("share button tapped")
    }
    share.backgroundColor = UIColor.blueColor()

    return [share, favorite, more]
}

I'm getting error:

Method 'tableView(:editActionsForRowAtIndexPath:)' with Objective-C selector 'tableView:editActionsForRowAtIndexPath:' conflicts with method 'tableView(:editActionsForRowAtIndexPath:)' from superclass 'UITableViewController' with the same Objective-C selector

I tried to add override but it didn't help - what causes this error and how can I fix it?

Community
  • 1
  • 1
user3766930
  • 5,629
  • 10
  • 51
  • 104

1 Answers1

6

The signature is slightly different: the return value should be [UITableViewRowAction]? not [AnyObject]?:

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?

You need the override as well.

pbasdf
  • 21,386
  • 4
  • 43
  • 75