Swift - Segue from a button inside a cell

I have a custom cell attached to the TableViewCell class, and I have a button inside this custom cell, I want the serum to press the button, which it transfers to another view controller, but:

performSegueWithIdentifier(identifier: String, sender: AnyObject?)

function is not recognized, how to fix it?

Edit:

Screen shot

+4
source share
3 answers

-performSegueWithIdentifier:declared in UIViewController. Therefore, you cannot just call it in a subclass UITableViewCell.

You can add an action to this button when you create a cell in a method -tableView:cellForRowAtIndexpath:. Then you can call the method -performSegueWithIdentifier:in this action method. Here is an example assuming we are in a subclass UITableViewController:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell

    cell.button.addTarget(self, action: "someAction", forControlEvents: .TouchUpInside)

    return cell
}

:

func someAction() {
    self.performSegueWithIdentifier("moveToView", sender: self)
}
+17

. @IBAction . .

0

If you are using Interface Builder:

Connect your first ViewView controller to secondViewController - and create a Segue ID.

Then you can use

performSegueWithIdentifier(identifier: String, sender: AnyObject?)
0
source

All Articles