‘presentModalViewController:setAnimated:’ is throwing an exception.

Discussion in 'iOS Programming' started by Aayush, Jun 12, 2010.

  1. macrumors newbie

    Aayush

    Joined:
    Nov 8, 2008
    Location:
    Siliguri, W.B., India
    #1
    Hello.

    I’m trying to get the ‘Add’ button on my navigation bar in the RootViewController of my navigation-based iPhone application to bring up a modal view controller. All I’ve done so far in the program is what I’ve listed below.

    I created a navigation-based app, uncommented the ‘viewDidLoad:’ method and added the following lines to it:

    Code:
    	UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addSimpleTest)];
    	self.navigationItem.rightBarButtonItem = addButton;
    	[addButton release];
    I then hit ⌘N, chose ‘UIViewController subclass’ as the type of file and enabled “With XIB for user interface”. I named it ‘SimpleTest.m’ and enabled “Also create SimpleTest.h”. Then I went back to ‘RootViewController.h’ and added the following method declaration:

    Code:
    - (void)addSimpleTest;
    In the corresponding implementation file, I wrote the following code for that method:

    Code:
    - (void)addSimpleTest
    {
    	SimpleTest *simpleTest = [[SimpleTest alloc] initWithNibName:@"SimpleTest.xib" bundle:nil];
    	[self presentModalViewController:simpleTest animated:YES];
    	[simpleTest release];	
    }
    And that’s it. That’s all I’ve done. It ought to work, right? When I run the program and tap on the ‘Add’ button, it crashes and throws the following exception:

    Code:
    2010-06-13 10:51:50.617 Testing[24725:207] *** -[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
    2010-06-13 10:51:50.621 Testing[24725:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '(null)'
    I’ve tried to use the debugger to figure out what is wrong and all I’ve managed to ascertain is that the crash happens when calling the ‘presentModalViewController:setAnimated:’ method and, for the life of me, I just cannot figure out what is wrong.

    I’m using Xcode version 3.2.3 (pre-release) 64-bit. The Xcode IDE version is 1680.0. The iPhone Simulator is at version 4.0 (204) and I’m running Mac OS X version 10.6.3.

    If anyone could lend me a helping hand here, I would really appreciate it. Thank you.
     
  2. thread starter macrumors newbie

    Aayush

    Joined:
    Nov 8, 2008
    Location:
    Siliguri, W.B., India
    #2
    Never mind. The problem was that the NIB name should not contain the “.XIB” extension. It’s working now.
     

Share This Page