2016-03-30 2 views
2

В моем приложении у меня есть класс, определяемый следующим образом:метод Tableview editActionsForrowAtIndexPath конфликтов селекторных Objective-C с методом из суперкласса

class MyTableViewController: UITableViewController { 

и внутри я хотел бы добавить функциональность считывания выбранных ячеек (из 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] 
} 

Я получаю ошибку:

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

Я попытался добавить override, но это не помогло - что вызывает эту ошибку и как я могу ее исправить?

+1

Выполняет ли изменение '-> [AnyObject]?' To '-> [UITableViewRowAction]?' Help? –

ответ

6

подпись немного отличается: возвращаемое значение должно быть [UITableViewRowAction]? не [AnyObject]?:

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

Вам нужен override, а также.

Смежные вопросы