Override returns secondary Viewcontroller error in Swift2

Asked

Viewed 29 times

0

I’m getting this message below while trying to make a Swipe on a cell of a Tableview. Remembering that I am doing this in a viewcontroller file and not in a tableViewController. It is possible?

Method does not override any method from ist superclass

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

Someone can give me a light?

  • 1

    You only need to override when subclassing Uitableview, as Voce himself said is Uiviewcontroller, so just remove override and connect your code (Uiviewcontroller) with a Iboutlet in your Uitableview

  • The problem is, it won’t work the way I want it to without the override. One question, I can create the separate class for the tableview inside a viewcontroller?

1 answer

2

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

1. To assign a delegate UITableView:

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

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

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

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

class ViewController: UIViewController, UITableViewDelegate {}

or

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

References:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.