Presenting a Modal Controller is causing my app to crash

Discussion in 'iOS Programming' started by zerocustom1989, Jun 18, 2010.

  1. zerocustom1989 macrumors regular

    Joined:
    Sep 5, 2007
    #1
    Hey guys, I've been racking my brain over this for the past hour and im just about out of ideas.

    I have the following code as activated by a button on an ActionSheet.

    Code:
    
    -(void) actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex {
    	if(buttonIndex != [actionSheet cancelButtonIndex]){
    		if (buttonIndex == ASSemesterButtonIndex) {
    			//SemesterAdd has been pressed. load the add semester modal view
    			SemesterAddViewController *addSemesterController = [[SemesterAddViewController alloc] initWithNibName:@"SemesterAddViewController" bundle:nil];
    			addSemesterController.delegate = self;
    			
    			Semester *newSemester = [NSEntityDescription insertNewObjectForEntityForName:@"Semester" inManagedObjectContext:self.managedObjectContext];
    			addSemesterController.semester = newSemester;
    			
    			UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addSemesterController];
    			[self presentModalViewController:navigationController animated:YES];
    			
    			[navigationController release];
    			[addSemesterController release];
    
    		}
    	}
    }
    
    
    
    I know this means that only the top button works, and that the other buttons do nothing but retract the sheet. My problem occurs with the following line:
    Code:
    [self presentModalViewController:navigationController animated:YES];
    
    I used some breakpoints and found that that line was causing my crash.

    If you guys have any hunches please let me know.

    Thank You.

    PS, Anyone know any good resources for learning to use the debugger in Xcode?
     
  2. zerocustom1989 thread starter macrumors regular

    Joined:
    Sep 5, 2007
    #2
    Gah, something was wrong with the viewdidload method in the viewcontroller for the modal view.

    I found it out by commenting a block of code out. Not sure how to find these errors in a more proper fashion.

    I'd delete this thread if I knew how. Thanks to the people that viewed this.
     
  3. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #3
    You could manual add a break point to the objc_exception_throw, this will cause the app to stop on any objc_exception. This from in the debugger window you can type "where" without the quotes. This can give you a stack trace and will allow you to back track to the line that is causing the crash.
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    It's not required to manually set a breakpoint on objc_exception_throw (anymore). Choose Run > Stop On Objective-C Exceptions and that's the same thing.
     
  5. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #5
    I guess im just used to the old way lol. Thanks for the tip though.
     

Share This Page