Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

idelovski

macrumors regular
Original poster
Sep 11, 2008
235
0
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.