Display Name
Display Name

Reputation: 1035

How to call a segue from a uitableview cell

I'm using storyboards and swift

I have a view which contains a tableview. Using storyboards i have arranged 5 different possible cells, each with their own custom class. Example is pasted below.

import UIKit

class AddNew_Date_Cell: UITableViewCell {

    @IBOutlet var Label: UILabel!
    @IBOutlet var textField: UITextField!

    func loadItem(var data:NSArray) {
        Label.text = data[0] as? String
    }
}

This works i can load the view and the tableview shows the cells as id expect. The above example is a label and a textfield.

When i select the textfield i want another popover to appear, Again this view has been drawn in storyboards and a segue made to it. "LoadPopover2".

Issue is how do i call the segue from UITableViewCell class?

if i try

self.performSegueWithIdentifier("PlayLoad", sender: self)

i get the error "'AddNew_Dae_Cell' does not have a member named 'performSegueWithIdentifier'

Thanks

Upvotes: 0

Views: 386

Answers (1)

Lucas Derraugh
Lucas Derraugh

Reputation: 7049

- performSegueWithIdentifier:sender: is a method on UIViewController, not UITableViewCell. To detect a tap on a particular cell, you're best to use the UITableViewDelegate to be notified on - tableView:didSelectRowAtIndexPath: and then perform the segue from within your controller. Inside your implementation you can just inspect the cell that is selected to see if it is of a particular type and based on that type you call that particular segue.

Upvotes: 1

Related Questions