0

A lot have people have had similar issues and I have read their solutions but I still can not get mine to work.

I connect the 2 views. I can not show the connection because I don't have the reputation to post images. I call the seque identifier GameOver.

Then I call the seque here:

if(self.lives == 0)
{
    [self performSegueWithIdentifier: @"GameOver" sender:self];
}

The application crashes at this point. What did I do wrong?

"libc++abi.dylib: terminating with uncaught exception of type NSException"

tnek316
  • 630
  • 1
  • 5
  • 16
  • 1
    Welcome to StackOverflow. Post the full error. – duci9y Jul 27 '14 at 05:42
  • Thanks. 2014-07-27 01:39:10.277 Memory[2604:60b] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'GameOver'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.' I am thinking this has something to do with it. – tnek316 Jul 27 '14 at 05:44
  • 1
    You need to change the segue's presentation style to modal in the storyboard. – ZeMoon Jul 27 '14 at 05:45
  • The view controller calling the `GameOver` segue isn't embedded in a navigation controller. Select your view controller in interface builder, then Editor menu > Embed in > Navigation Controller. Push segues can only be used with navigation controllers. – duci9y Jul 27 '14 at 05:45

3 Answers3

1

You need to embed your view controller in a UINavigationController since push segues can't be used without a navigation controller. See the screenshot below for instructions:

Embed in navigation controller

rebello95
  • 8,486
  • 5
  • 44
  • 65
  • I didn't want to have a navigation controller. akash was right to tell me to switch it to modal. Thanks for helping me understand though – tnek316 Jul 27 '14 at 05:59
  • To use push segues, you have to have a navigation controller. Is there a reason you don't want a navigation controller? You can remove the animation between view controllers if that's your concern. – rebello95 Jul 27 '14 at 06:00
  • No I do not want the back bar to come in to my view after the seque. When you switch it to modal it does not automatically put the navigation controller bar at the top – tnek316 Jul 27 '14 at 06:00
  • You can use this in the `viewDidLoad` of the view controller you're segueing to: `[self.navigationController setNavigationBarHidden:TRUE animated:FALSE];`, that will hide the nav bar. – rebello95 Jul 27 '14 at 06:02
  • Is there a problem with making it modal? I'm not trying to argue, just trying to understand. – tnek316 Jul 27 '14 at 06:08
  • I don't think so, I guess it just depends on what you want to do. I've never tried the modal method before, so your method could be better. – rebello95 Jul 27 '14 at 06:08
  • Ok well I will leave it modal for now. But thank you for showing me the other options – tnek316 Jul 27 '14 at 06:11
1

Looking at the error log , I think you don't have navigation controller in your app. Your segue is push. In order to push a new view controller , you must have UINavigationController setup before you perform the push segue operation.

To fix this issue - Select your view controller in Storyboard -> Click on Editor -> Embed In -> Navigation Controller. This will add navigation controller your app & now onwards you can perform push & pop operations successfully.

iOSAppDev
  • 2,755
  • 4
  • 39
  • 77
0

Akashg answered my question. Needed to switch the seque style to "modal". "Push" style needs to be embed with navigation controller, or tab bar controller, according to duci9y.

Here is where I found the answer to the difference between modal and push segue.

What is the difference between Modal and Push segue in Storyboards?

Modal presents the new view from the current view.

Push puts a controller in between the two views.

Thanks for everyones input. I tried to keep the answer simple so people can get their answer quick

Community
  • 1
  • 1
tnek316
  • 630
  • 1
  • 5
  • 16