0

This is so weird to me. Yesterday I think I had this same crash once on an iPhone4 ios6 device. Today I tried running my app in the simulator and it is reliably crashing on me when I call pushViewController. Here is the code that crashes it.

    PFObject *selectedGame = [self.myTurnList objectAtIndex: index];
    [self.myTurnList removeObjectAtIndex:index];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    GuessWordController *guessWord = [storyboard instantiateViewControllerWithIdentifier:@"GuessWordController"];
    guessWord.game = selectedGame;
    //[self performSegueWithIdentifier:@"toGuessWord" sender:self];
    [self.navigationController pushViewController:guessWord animated:NO];
    return;

I've put a bunch of NSLog's in there and everything seems to look great all the way to the return statement. However I get 'EXC_BAD_ACCESS' thrown and no output to the debugger. I also have NSLog's in my GuessWordController's viewDidLoad and none of them show up.

I have tried changing pushViewController to doing a segue that I set up with the storyboard instead and that seems to work. But I wanted to do it with pushViewController because I don't want the animation.

Is there any reason the way I have this set up would cause the app to crash, specifically ios5.1?

Chase Roberts
  • 9,082
  • 13
  • 73
  • 131
  • Did you set the Storyboard Id for the controller to be "GuessWordController" in the storyboard? Or are you just referencing the class? – Fernando Mazzon Jan 03 '13 at 20:45
  • I guess you are messaging a released object. Try turning on zombies. http://stackoverflow.com/questions/2190227/how-do-i-set-up-nszombieenabled-in-xcode-4 – nielsbot Jan 03 '13 at 20:52
  • If you get a segfault (that's a less fancy name for the `EXC_BAD_ACCESS` error), then you're sending that message to a deallocated object. Don't do that. –  Jan 03 '13 at 20:57
  • The storyboard ID is in fact "GuessWordController", & I am using ARC. Messaging a released/deallocated object could be the problem. But shouldn't ARC handle that? And why would it work on iOS6 99% of the time? Does iOS5 not have ARC? – Chase Roberts Jan 03 '13 at 21:32
  • Does it crash if you remove the return? – rdelmar Jan 03 '13 at 23:22

1 Answers1

0

Why not use the segue and create a custom segue with no animation?

It's a lot easier than what you're trying to do.

From the docs here...

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomSegues/CreatingCustomSegues.html#//apple_ref/doc/uid/TP40007457-CH16-SW1

You can use this function...

- (void)perform
{
// Add your own animation code here.

    [[self sourceViewController] presentModalViewController:[self destinationViewController] animated:NO];
}

Then delete all that stuff you have and just use [self performSegueWithIdentifier:@"toGuessWord" sender:self]; instead.

Then in prepareForSegue you will need...

GuessWordController *controller = segue.destinationViewController;

controller.game = selectedGame;

This should work.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • Trying to create a custom segue, and I am having a similar problem. -(void)perform{ [[[self sourceViewController] navigationController] pushViewController:[self destinationViewController] animated:NO]; } Do I need to include anything else? – Chase Roberts Jan 03 '13 at 22:09
  • That's exactly what I did, except I want to do a push, because I need to keep the Nav controller around and I want to be able to pop back to the previous view. So I did pushViewController instead of presentModalViewController. But apparently pushViewController is the source of all my problems.. – Chase Roberts Jan 04 '13 at 02:31
  • You need to read about segues and storyboards. The segue does the push for you and creates the view controller for you. You shouldn't be creating the VC yourself. – Fogmeister Jan 04 '13 at 10:33
  • I know how to do segues and storyboards. The reason I created the VC myself is because I wanted to do a basic push with no animation. I have done this several times before and know that it should work. But for some reason this instance is being deallocated before I can use it. – Chase Roberts Jan 04 '13 at 16:29
  • If you're usin a segue then you shouldn't be creating your own VC at all. The storyboard does that for you. You just select your custom segue class in the storyboard file and then let the segue do the work. – Fogmeister Jan 04 '13 at 16:44