I have presented a UINavigationController containing UIViewController on self object with following code
drawController = [[DrawImageViewController alloc] initWithNibName:nil bundle:nil];
[drawController setDrawControllerDelegateObject:self];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:drawController];
[self presentModalViewController:nav animated:YES];
[nav release];
But when before calling the above code for second time i wanna know whether the current view controller appearing on screen is drawController. I am using following code
if (drawController && [drawController isBeingPresented])
But it is not working for me and also it is for iOS 5.0 so i am stuck here. Please help me to know how should i come to know the current UIViewController appeared on screen is of which class and whether drawContoller is still presented on screen or not? Sorry for my typo mistakes if there is any. Any help will be appreciated.
Thanks Neha Mehta
The view's window property is non-nil if a view is currently visible, so check the main view in the view controller: Invoking the view method causes the view to load (if it is not loaded) which is unnecessary and may be undesirable. It would be better to check first to see if it is already loaded.
In addition, you can check for UINavigationController and ask for its topViewController or even check for UITabBarController and ask for selectedViewController . This will get you the view controller that is currently visible to the user.
If you need to find the view controller that is responsible for a particular view, the easiest thing to do is walk the responder chain. This chain is built into all iOS apps, and lets you walk from one view up to its parent view, its grandparent view, and so on, until it reaches a view controller.
Use navigationController's visibleViewController property
and isKindOfClass method
to know whats on top
:
if([self.navigationController.visibleViewController isKindOfClass:[yourcontroller class]])
//exists
else
//not exists
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With