5

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!

Martin Muldoon
  • 3,388
  • 4
  • 24
  • 55
  • did you name the segue in storyboard ? – Teja Nandamuri Feb 23 '16 at 16:32
  • Yes I did. I've read you can't connect a Xib to the storyboard to create a segue, so I've connected the two view controllers via the storyboard. Named the Indentifier, and now I'm simply trying to call the segue programmatically when I click a button on the Xib. I can't call performSegueWithIdentifier for some reason. Says the member doesn't exist. – Martin Muldoon Feb 23 '16 at 16:45

1 Answers1

5

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?
Community
  • 1
  • 1
Alvaro
  • 286
  • 3
  • 15