Override returns error in secondary ViewController in Swift2

0

I'm getting this message below when trying to swipe into a cell in a TableView. Reminding me that I'm doing this in a viewcontroller file and not in a tableViewController. Is it possible?

  

Method does not override any method from ist superclass

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

Can someone give me a light?

    
asked by anonymous 08.07.2016 / 21:58

1 answer

2

Considering that you have an instance of a UITableView in your ViewController , you need to do three things:

1. Assign a delegate to your instance of UITableView :

// considerando o ViewController onde tableView foi instanciado,
// implementa UITableViewDelegate
tableView.delegate = self

2. Implement the same method you are using but without override :

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

3. Assign an implementation or create an extension of UITableViewDelegate to your class:

class ViewController: UIViewController, UITableViewDelegate {}

or

extension ViewController: UITableViewDelegate {
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
  // implement me
}

References:

10.07.2016 / 18:20