5

I am using xcode 7 beta and swift 2.0. I am following a tutorial (youtube.com/watch?v=PKOswUE731c).

In short i have a storyboard with 3 views; a protected vc, a login vc and RegisterViewController. I have set 2 segues

segue modal with protected_vc <-> login_vc identified with loginView

segue modal on a button in login_vc <-> RegisterViewController identified with registerView

I encountered a problem when with a register button on my login vc. If i click the register button it crashes the app and i get the message 'Receiver (<registerLogin.RegisterViewController: 0x7f97235f6140>) has no segue with identifier 'loginView''

Now i notice in the tutorial selecting a segue gives another dropdown, in my case i only see push - modal -popover - replace and custom. Could this be the cause??

Or this part ViewController

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

enter image description here

Complete code for RegisterViewController is

import UIKit

class RegisterViewController: ViewController {


    @IBOutlet weak var userEmailTextField: UITextField!

    @IBOutlet weak var userPasswordTextField: UITextField!
    @IBOutlet weak var repeatPasswordTextField: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    @IBAction func registerButtonTapped(sender: AnyObject) {

        let userEmail = userEmailTextField.text
        let userPassword = userPasswordTextField.text
        let repeatPassword = repeatPasswordTextField.text

        //No empty fields
        if((userEmail!.isEmpty || userPassword!.isEmpty || repeatPassword!.isEmpty)){
            //Display alert message
            displayMyAlertMessage("All fields required")
            return
        }
        //Check if passwords match
        if(userPassword != repeatPassword){
            //Display alert message 
            displayMyAlertMessage("Passwords mistakes")
            return
        }

        //Store data
        NSUserDefaults.standardUserDefaults().setObject(userEmail, forKey: "userEmail")
        NSUserDefaults.standardUserDefaults().setObject(userPassword, forKey: "userPassword")

        NSUserDefaults.standardUserDefaults().synchronize()

        //Display alert message with confirmation
        let myAlert = UIAlertController(title: "Alert", message: "Registration successful", preferredStyle: UIAlertControllerStyle.Alert)
        let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default) { action in
            self.dismissViewControllerAnimated(true, completion: nil)
        }


    }


    func displayMyAlertMessage(userMessage:String){
        let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert)

        let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)

        myAlert.addAction(okAction)

        self.presentViewController(myAlert, animated: true, completion: nil)
    }

}

and the complete error message (manually wrapped first line):

2015-10-11 07:17:57.378 registerLogin[667:10462] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: 'Receiver (<registerLogin.RegisterViewController: 0x7fb7f978d4c0>) 
has no segue with identifier 'loginView''
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000102d249b5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000104923deb objc_exception_throw + 48
    2   UIKit                               0x00000001036caba3 -[UIViewController shouldPerformSegueWithIdentifier:sender:] + 0
    3   registerLogin                       0x0000000102b4260f _TFC13registerLogin14ViewController13viewDidAppearfS0_FSbT_ + 127
    4   registerLogin                       0x0000000102b42661 _TToFC13registerLogin14ViewController13viewDidAppearfS0_FSbT_ + 49
    5   UIKit                               0x00000001036cd82e -[UIViewController _setViewAppearState:isAnimating:] + 830
    6   UIKit                               0x00000001036ce1b0 -[UIViewController _endAppearanceTransition:] + 262
    7   UIKit                               0x000000010369950e -[UIPresentationController transitionDidFinish:] + 827
    8   UIKit                               0x0000000103857c17 -[_UICurrentContextPresentationController transitionDidFinish:] + 42
    9   UIKit                               0x000000010369c97e __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183
    10  UIKit                               0x0000000103eb105c -[_UIViewControllerTransitionContext completeTransition:] + 101
    11  UIKit                               0x00000001036963fb -[UITransitionView notifyDidCompleteTransition:] + 252
    12  UIKit                               0x000000010369610c -[UITransitionView _didCompleteTransition:] + 1344
    13  UIKit                               0x0000000103698878 -[UITransitionView _transitionDidStop:finished:] + 104
    14  UIKit                               0x00000001035c3a63 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 241
    15  UIKit                               0x00000001035c3e12 -[UIViewAnimationState animationDidStop:finished:] + 80
    16  QuartzCore                          0x000000010799bd70 _ZN2CA5Layer23run_animation_callbacksEPv + 308
    17  libdispatch.dylib                   0x000000010540d4bb _dispatch_client_callout + 8
    18  libdispatch.dylib                   0x00000001053f53ff _dispatch_main_queue_callback_4CF + 1738
    19  CoreFoundation                      0x0000000102c84e69 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    20  CoreFoundation                      0x0000000102c463b9 __CFRunLoopRun + 2073
    21  CoreFoundation                      0x0000000102c45918 CFRunLoopRunSpecific + 488
    22  GraphicsServices                    0x000000010722dad2 GSEventRunModal + 161
    23  UIKit                               0x000000010354199e UIApplicationMain + 171
    24  registerLogin                       0x0000000102b4323d main + 109
    25  libdyld.dylib                       0x000000010544292d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I have set the segues

enter image description here

and from the register button enter image description here

A find in project on the term loginView only gives 2 search results see image, so i don't get where RegisterViewController "thinks" it needs loginView

enter image description here

Rainer Schwarze
  • 4,725
  • 1
  • 27
  • 49
alex
  • 4,804
  • 14
  • 51
  • 86

1 Answers1

15

Your class RegisterViewController is a subclass of ViewController, but likely should be a subclass of UIViewController. Probably your ViewController class is the main view controller already created when creating a new project.

When RegisterViewController is a subclass of ViewController, it also inherits the viewDidAppear method. Therefore when it appears it calls performSegue... with loginView, but now with the instance of RegisterViewController there is no loginView segue. Hence the exception.


Original answer below, which is the likely reason for an exception of the kind has no segue with identifier '...name...':

Likely your segue identifier is not set or misspelled.

Segue ID

  1. Click on the segue
  2. Make sure the Utilities panel on the right hand side is visible
  3. Make sure the Attributes inspector is visible
  4. Check the value for "Identifier" under "Storyboard Segue" (in the screenshot it is "infoSegue")
Rainer Schwarze
  • 4,725
  • 1
  • 27
  • 49
  • 1
    Are you calling `performSegue...` with the segue identifier in the correct place? The error message states, that `RegisterViewController` does not have a `loginView` segue - from what I understand, it should indeed not have it. `ViewController` should have that segue. Do you have a call using `loginView` in `RegisterViewController` ? – Rainer Schwarze Oct 10 '15 at 22:47
  • yes i am calling perfomrSegue in ViewController with `override func viewDidAppear(animated: Bool) { self.performSegueWithIdentifier("loginView", sender: self);}` i have made another edit to my post with the RegisterViewController code – alex Oct 11 '15 at 05:22
  • btw doing a simple find in project als gives me just storyboard and viewcontroller see last image in my post – alex Oct 11 '15 at 05:39
  • 1
    The super class of RegisterViewController should likely be UIViewController and not ViewController. - I'm changing my answer. – Rainer Schwarze Oct 11 '15 at 06:48
  • HOORAY, sorry i know this is not the stackoverflow way but you made my sunday indeed i overlooked UIViewController and used ViewController. I had a short night sleep as this simple thing was killling me. But thanks to you i can enjoy sunday without a macbook ;). Have a nice weekend! – alex Oct 11 '15 at 07:04
  • 2
    Thanks - glad I could help. I know the feeling too well, when something doesn't work and rest is not to be found :-) – Rainer Schwarze Oct 11 '15 at 13:34
  • My rootview controller is a sub class of UITableViewController, and i cannot change it to be a sub class of UIViewController , but I get the same error irrespective of what I try to do ..! Can someone help ? – AnxiousMan Apr 05 '16 at 10:09
  • @ManeeshSharma You should not need to change it to `UIViewController` (`UIViewController` is a super class of `UITableViewController` anyway). What exact error do you get? – Rainer Schwarze Apr 05 '16 at 13:02