Parent View Controller

Discussion in 'iOS Programming' started by idelovski, May 11, 2009.

  1. idelovski macrumors regular

    Joined:
    Sep 11, 2008
    #1
    I have two view controllers, one is presenting the other modally with -presentModalViewController:animated:, and the second controller has a view with a button that should close it by calling parents -dismissModalController which just cals -dismissModalViewControllerAnimated:.

    The problem is that I can't use parentViewController property of second controller to set a target for the dismissing action:
    Code:
    [theButton addTarget:self.parentViewController 
                  action:@selector(dismissModalController) 
         forControlEvents:UIControlEventTouchUpInside];
    
    This ends with unhandled exception when I press the button.

    Then I added realParentController property and -initWithRealParent: method to the second controller and when I changed the code above to use that new property, the modal view closed ok without any unhandled exceptions.
    Code:
    [theButton addTarget:self.realParentController 
                  action:@selector(dismissModalController) 
         forControlEvents:UIControlEventTouchUpInside];
    
    I can see in debugger while I'm in -loadView that the parentViewController property of the second controller is not nil, but why it isn't the right pointer to the parent controller?
     

Share This Page