I have presented the viewController which contains a navigation controller whose view is loaded from another nib with the UITableView in it. I would like to dismiss that presented viewController from the UITableViewController. I have tried every combination of self.parentViewController and self.navigationController and self.navigationController.parentViewController but I am still not able to dismiss it. How and what is the best way for it to be dismissed?
A:
I have never gotten self.navigationController.parentViewController
to work as advertised, but this does work for me:
NSArray *viewControllerArray = [self.navigationController viewControllers];
int parentViewControllerIndex = [viewControllerArray count] - 2;
[[viewControllerArray objectAtIndex:parentViewControllerIndex] myParentViewMethod:arg1 withArg2:arg2 ...];
Alex Reynolds
2009-09-23 07:38:14
I could not get this to work, I only had one item in the array and that still did not dismiss the view. It may have to do with the way that I created it. I add a new UIViewController with XIB and create an outlet for a UINavigationController, I then hook that up. I next create a UITableViewController with XIB. Back in the UIViewController's XIB, I set it to load that new nib and set the class to the class of the UITableViewController.
woody993
2009-09-23 12:21:15
A:
Is this not working?
[myViewController presentModalViewController:otherController animated:YES];
// ...
[myViewController dismissModalViewControllerAnimated:YES];
slf
2009-09-23 18:21:01
I need to process the data from the UITableView and am doing this inside the UITableViewController, I need to dismiss the parentViewController, but that does not work
woody993
2009-09-24 02:40:17
A:
It sounds like you've painted yourself into a corner a bit with your hierarchy, but that's ok I think we can fix it. There the two "usual" ways of doing this are:
- From controller A, present controller B, from B do work, from B dismiss, return to A
- From controller A, present controller B, from B do work, raise event via delegate protocol to A, from A dismiss B which returns control to A
In your current situation, this may require an uncomfortable ammount of refactoring, in which case it may be easier to just expose a handle to the other controller as a property, just make sure it's a weak reference like so:
@interface ControllerB : UIViewController
{
ControllerA* controllerA;
}
@property (readwrite, nonatomic, assign) ControllerA* controllerA; // weak reference
@end
Or however you like, the point is to scope the variable properly so that it's available when you need it.
slf
2009-09-24 14:56:31