Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perform a segue from an Xib to ViewContoller

Tags:

xcode

swift

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!

like image 213
Martin Muldoon Avatar asked Feb 23 '16 15:02

Martin Muldoon


1 Answers

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?
like image 108
Alvaro Avatar answered Sep 28 '22 12:09

Alvaro