1

I have a project in which I have a storyboard. The storyboard contains several view controllers. I'll simplify it and omit the unnecessary details. Within a Navigation Controller, there are several UIViewControllers hooked up with segues. (see screenshot below...)enter image description here

From left to right on the bottom row it goes Navigation Controller ➞ VC1 ➞ VC2. VC1 also has a manual segue to VC3 on the top row which goes VC3 ➞ VC4. VC1 is the starting view controller of the app. There two segues connecting from VC1. The segue from VC1 ➞ VC2 is the primary segue and from VC1 ➞ VC3 is the secondary. The secondary segue will be called programmatically when the user runs the app for the first time as a sort of welcome/getting started sequence.

I set this up going off of this post here, referencing the second most upvoted post in which the user suggests a segue between the starting VC file itself and the view of the other VC and then calling performSegueWithIdentifier.... here is the problem.

When running this app, there are no compile-time errors. It all looks good. It loads up, and I have this set to go in the view did load, which for now I am forcing it to run as if it were the first time like so...

override func viewDidLoad() {
    super.viewDidLoad()

    let firstVisit = true

    if firstVisit == true {
        self.performSegueWithIdentifier("welcomeSegue", sender: self)
    }

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

So it loads up. I can tell it attempts to show VC1 before VC3 promptly gets pushed on top as desired. VC3 is displayed, brilliant. The issue occurs when I press the one and only button on VC3 that should perform a typical segue from VC3 ➞ VC4. This is when I get the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<X.VC1>) has no segue with identifier 'welcomeSegue''

Now the strange thing to me that I cannot figure out is that, even though VC3 has been properly presented, it is VC1 that this error originates from as denoted by the Receiver (<X.VC1>). I'm stumped. All of the errors I have found online show other solutions that have not worked for me. If you don't believe me when I say I know the spelling is right, A) It properly loaded the view controller, B) here is a screenshot anyway.enter image description here

I DUN GET IT :[ Let me know if you have advice. Thanks all.

** AGAIN, JUST AS A REMINDER, THIS APP DOES PROPERLY LOAD AND DISPLAY VC3 AS IT SHOULD. THE ERROR OCCURS AFTERWARDS WHEN I ATTEMPT TO SEGUE TO VC4 BUT THAT SEGUE IS NORMAL THROUGH INTERFACE BUILDER WITH NO IDENTIFIER BECAUSE IT WILL NEED NO LINK TO THE CODE AS THE SEGUE TO VC3 DOES.

EDIT: Here is a sample project that functions properly. I cannot distinguish a difference that sets mine apart.

EDIT #2: I admit to making a dumb mistake. The marked solution has found it and corrected it and the project now functions as desired. Thank you all.

Community
  • 1
  • 1
willbattel
  • 1,040
  • 1
  • 10
  • 37
  • @Raja Vikram same result, I'm afraid. Good idea though. – willbattel Jul 03 '15 at 04:41
  • Try using your code in `viewWillAppear` / `viewWillLayoutSubviews` – Raja Vikram Jul 03 '15 at 04:41
  • @Dharmesh Kheni Yes, I'll add one momentarily. – willbattel Jul 03 '15 at 04:50
  • Well the sample project actually does exactly what it should... I'm going to fiddle around with the real one and see if I can come up with anything. – willbattel Jul 03 '15 at 04:57
  • where is sample project? – Dharmesh Kheni Jul 03 '15 at 05:01
  • I'll upload the sample (that works properly) and point out where it doesn't work in the real project. It is strange because I'd expect this error to be called at a different time but it frankly shouldn't be called at all because it has nothing to do with that view controller. – willbattel Jul 03 '15 at 05:02
  • try to figure what problem is by comparing sample project and original project..:) – Dharmesh Kheni Jul 03 '15 at 05:04
  • lol right... I'm trying. I have tried removing and reinserting the segues as the other project has them but nothing. Gah its so frustrating because I'm sure it's one little thing that I'm going to facepalm through my head for. – willbattel Jul 03 '15 at 05:06
  • ok I will check your sample code. – Dharmesh Kheni Jul 03 '15 at 05:09
  • There is literally one line of code. Just one line in the viewDidLoad. Everything else is storyboard, which is why I'm so baffled I can't find it. Worst comes to worst I'll reassemble the storyboard tomorrow and give it a whirl. – willbattel Jul 03 '15 at 05:13

2 Answers2

1

I study your project and found that you assign wrong class to your VC4 as shown in below image:

enter image description here

Just remove that HomeVC and assign new class to it and it will work fine.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
0

It seems like that you have not set segue identifier. performSegueWithIdentifier method trying to called welcomeSegue. but its don't available so crash happen.

To removed the following crash, followed the steps.

Step 1 : Tap on segue between two UIViewController. like as enter image description here

Step 2 : Now check property of that segue at right side of panel. where write identifier name as welcomeSegue.. like as

enter image description here

Now run your project, you will face any crash..

Jatin Patel - JP
  • 3,725
  • 2
  • 21
  • 43