Martin Muldoon
Martin Muldoon

Reputation: 3428

Perform a segue from an Xib to ViewContoller

I have a Xib file with a button. I want to segue to another view controller when the button is clicked. I've created a segue between the view controllers in StoryBoard and created an identifier, but can't seem to call it programatically.

@IBAction func buttonAction(sender: UIButton)
{
 self.performSegueWithIdentifier("SegueToPostDetail", sender: sender)
}

Xcode error is "....has no member 'performSequeWithIdentifier'

Thanks!

Upvotes: 5

Views: 5924

Answers (1)

Alvaro
Alvaro

Reputation: 286

You can't call performSegueWithIdentifier in a Xib class, only in a UIViewController class. So you have 2 solutions:

  1. Have the button in the UIViewController and when the button is clicked to call performSegueWithIdentifier.
  2. Create a delegate in Xib class and UIViewController class implements that delegate protocol. How do I set up a simple delegate to communicate between two view controllers?

Upvotes: 5

Related Questions