EXC_BAD_ACCESS when loading XIB

Discussion in 'iOS Programming' started by dbramhall, Oct 22, 2011.

  1. dbramhall macrumors newbie

    Aug 1, 2011
    England, UK
    I am trying to load an XIB with the code below:

    -(IBAction)openNewViewButtonPress:(id)sender {
    	[[NSBundle mainBundle] loadNibNamed:@"NewView" owner:self options:nil];
    but every time I press on the UIButton that it's linked to, the app crashes and Xcode throws EXC_BAD_ACCESS at me and I honestly have no idea why. What I have done is have a welcome screen and then once the user presses one of the UIButtons, the next view loads using loadNibNamed (this works fine) but when I try to load another view using the loadNibNamed method, the application doesn't work - any ideas?

    Thanks in advance!
  2. chown33, Oct 22, 2011
    Last edited: Oct 22, 2011

    chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Change your code to this:
    -(IBAction)openNewViewButtonPress:(id)sender {
      NSLog( @"should load NewView" );
    //	[[NSBundle mainBundle] loadNibNamed:@"NewView" owner:self options:nil];
    Now, when you click the button, what happens?

    If you see the message, and no crash, then the problem is in the actual loading of the nib. Maybe the nib is damaged, or it refers to something that doesn't exist, such as a class, object, or resource.

    If you still see a crash, then the problem is something else. Maybe some object is under-retained or over-released, and is being dealloc'ed when you don't expect it. Run under Instruments with zombies enabled (google search terms: ios instruments zombies).

    Using NSLog like this is a primitive type of debugging.

    You should learn how to use the debugger instead of just inserting NSLog's. Then you can set a breakpoint on the method, and it will stop at that point. You will eventually need to learn how to use the debugger, so you should do it now, before the problems become more difficult. It's much easier to learn how the debugger works when your program is working, than when it's crashing.

    You should also learn how to read crash-log stack-traces. Or at least post them so others can describe how to read them. Here's an example of a stack-trace.

Share This Page