Segues Initiated Directly from View Controllers Warning in Storyboard Xcode

why show this warning: Unsupported Configuration: Segues initiated directly from view controllers must have an identifier

This happens when you create the segue by dragging from the viewController, rather than from say a UIButton or other element. The reason is that in order to execute the segue programmatically you need to specify an identifier like this:

[self performSegueWithIdentifier:@"BOOK_LEAVE_SEGUE" sender:sender];

Otherwise there is no way of knowing which segue to perform.

So click on the segue in the storyboard, open attributes pane and give it an identifier.

Where you should set the identifier

What does this Xcode error mean?

From this SO question: Segues initiated directly from view controllers warning in storyboard xcode

"Segues initiated directly from view controllers must have an
identifier for use with -[UIViewController
performSegueWithIdentifier:sender:]

This warning occurs when you drag a segue from the View Controller
icon (aka, not a segue from a button or action) and don't give it a
segue name.

You have to give these ones a name or else there's no way to call them
programmatically... which is the only reason why you would link a
segue like this.

You should be able to double click the warning to have the storyboard
bring up the offending segue so that you can add a name to it."

Can't find segues without identifiers

a master list of segues that I can look at

Absolutely. Control click on the storyboard's listing in the Project navigator and choose Open As > Source Code. Now you can read — and search — the storyboard as XML. Look for a <segue ... /> without an identifier attribute.

Can you read the storyboard segue identifier in the receiving view

I guess you are looking for the below method

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    DestinationViewController *dvc = segue.destinationViewController;
    dvc.segueIdentifier = segue.identifier;
    if ([segue.identifier isEqualToString:@"Button 1"]) {
    //
    }
    }

Changing view controllers programatically and using segues

The problem is that you are loading HomeViewController as the root view controller:

let homeViewController = storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController
view.window?.rootViewController = homeViewController
view.window?.makeKeyAndVisible()

Instead, you want to load a UINavigationController as the root. Give the navigation controller in your storyboard an ID (such as "mainNavController") and change your startup code to:

let navController = storyboard?.instantiateViewController(identifier: Constants.Storyboard.mainNavController)
view.window?.rootViewController = navController
view.window?.makeKeyAndVisible()

Now, HomeViewController will be loaded as that navigation controller's "root" controller, and your segues will "push" instead of "present".

Note: I'm assuming your current code (with the optional storyboard? and view.window?) already working correctly.



Related Topics



Leave a reply



Submit