0

I have written my Spotlight API code and it seems to be working okay. I can check it out in the spotlight but there's only one problem :

It won't take me to the desired view controller! How do I do that? I've added a

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "showIt" {

        let ThatVC = segue.destinationViewController as! ItThat


    }
}

but it still won't take me to the right spot. Where am I going wrong?

Amit Kalra
  • 4,085
  • 6
  • 28
  • 44

1 Answers1

0

prepareForSegue is used to notify the view controller that a segue is about to be performed (what data to prepare, confirms destination, etc). prepareForSegue is only called when a segue has already been initiated. It does not however perform the segue itself.

If your segue is unconditional, just use a standard segue in Interface Builder (pull from the UIButton to your destination scene).

If your segue is conditional, pull from the UIButton's parent scene to the destination scene in Interface Builder. Once this is finished, you can create a new @IBAction and perform a segue manually.

 @IBAction func fooAction() {
      performSegueWithIdentifier("showIt", sender: self)
 }

Just make sure "showIt" is the segue's identifier.

enter image description here

Willow Bumby
  • 41
  • 1
  • 1
  • 5
  • That's what I have. I get a SIGABRT error when I run it. – Amit Kalra Sep 02 '15 at 23:55
  • Remove your `prepareForSegue`. It's not doing anything. Make sure you've connected the segues/identifiers/ `@IBActions` up correctly. – Willow Bumby Sep 02 '15 at 23:57
  • They're setup. The SIGABRT disappears when the prepareForSegue is gone, but it's also removing the purpose I need it for. When I search for whatever in spotlight, and press it, it should take me to my view controller. – Amit Kalra Sep 02 '15 at 23:59