Is it possible to check inside ViewController class that it is presented as modal view controller?
views:
221answers:
3
+2
A:
If there isn't, you can define a property for this (presentedAsModal
) in your UIViewController subclass and set it to YES
before presenting the ViewController as a modal view.
childVC.presentedAsModal = YES;
[parentVC presentModalViewController:childVC animated:YES];
You can check this value in your viewWillAppear
override.
I believe there isn't an official property that states how the view is presented, but nothing prevents you from creating your own.
hgpc
2010-05-09 18:31:10
RIght and this is what i have did but I was looking for some other neat solution. Thanks.
lukewar
2010-05-10 08:35:30
+3
A:
This should work.
if(self.parentViewController.modalViewController == self)…
kubi
2010-05-09 18:47:38
Unfortunately this does not work. It was my first try. But returned modalViewController ins nil :(.
lukewar
2010-05-10 08:34:49
If you just get 'self.parentViewController' does it return the correct parent object?
kubi
2010-05-10 09:35:25
The problem might be that your UIViewController subclass is inside a UINavigationController or a UITabBarController (or both), in which case you might need to dig a bit more in the view hierarchy to find out the parent that was presented as a modal view controller.
hgpc
2010-05-10 22:30:56
A:
A hack like this might work.
UIViewController* child = self;
UIViewController* parent = child.parentViewController;
while (parent && parent.modalViewController != child) {
child = parent;
parent = child.parentViewController;
}
if (parent) {
// A view controller in the hierarchy was presented as a modal view controller
}
However, I think my previous answer is a cleaner solution.
hgpc
2010-05-10 22:39:59