pushViewController Not Working on iOS 5 (OK on iOS

2019-08-07 04:59发布

问题:

I have a UINavigationController that displays several buttons on screen. They all simply use the line:

myViewController *newView = [[myViewController alloc] initWithNibName:@"myViewController"
                                                                          bundle:nil];
[[self navigationController] pushViewController:newView animated:YES];

to transition to the next view. I have one such view controller however that results in a crash at this very line ONLY on iOS 5. It works perfectly fine on iOS 6. I am baffled. There are no real details to the crash. It is a SIGABRT that highlights the main.m line:

exitStatus = UIApplicationMain( argc, argv, nil, NSStringFromClass([ApplicationDelegate class]));

I have no clue...

回答1:

  1. You Need to unCheck the Auto Layout.

  1. And make sure you are changing here also.. select ios 5.1



回答2:

Try this line:

myViewController *newView = [[myViewController alloc] initWithNibName:@"myViewController"
                                                                              bundle:[NSBundle mainBundle]];

in place of:

myViewController *newView = [[myViewController alloc] initWithNibName:@"myViewController"
                                                                          bundle:nil];


回答3:

I have experimented a similar issue an here are the steps that I feel need to be considered:

  • (if you are using xib file) like Venkat Manohar Perepa mentioned, check that Use Auto Layout is turned off as it is an iOS 6 specific feature.
  • (if you are using xib file) look at the content of the xib file that is used when presenting your viewcontroller and check that there is no class that are iOS6 specific (e.g: NSLayoutConstraint)
  • Last (and that was the issue I was facing) you should check if the crash appear on a device that has iOS5 installed. If it doesn't but still crash on the simulator remove the application you have installed by choosing iPhone Simulator > Reset Content and Settings.