简体   繁体   中英

Swift - Fatal Error on Performing Segue

My iOS app is crashing when I run the following line of code after the push of a standard UIButton:

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

The segue identifier name is correct as I copied and pasted the name from the sidebar into the code. Upon remove the code the app stops crashing when the button is pressed.

The error I get is:

Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1002544fc)

And in the Output box:

fatal error: unexpectedly found nil while unwrapping an Optional value

error is somewhere else but for clearity.

1)put breakpoint on seguing line and note is control is reaching to segue line.

Or

2) following put your segue for testing:

override func viewDidAppear(animated: Bool) {
   self.performSegueWithIdentifier("loginAttempt", sender: self)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
   if (segue.identifier == "loginAttempt") {
        print("Hi segue is working")
   }
}

if it prints line then segue is working .

I had a similar problem and after many hours of frustration I found my own problem. Ultimately, the problem was that I had added new code in my ViewController class. The page I was segueing too had never been given a designated class and default to the ViewController class. When it tried to run the code for that class, the new view controller was missing elements found in the code and caused the crash.

I simply created a new class to give to the page that I was segueing too and everything worked fine again!

I'm not certain that that is your problem but I hope that at least helps a little bit with where the problem might be!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM