Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check current view controller over screen in ios

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

like image 940
Neha Mehta Avatar asked Oct 16 '12 12:10

Neha Mehta


People also ask

How do I know if a ViewController is visible?

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.

How do I get a top view controller?

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.

How do I find the view controller?

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.


1 Answers

Use navigationController's visibleViewController property and isKindOfClass method to know whats on top:

if([self.navigationController.visibleViewController isKindOfClass:[yourcontroller class]])
   //exists
else
   //not exists
like image 86
Paresh Navadiya Avatar answered Sep 20 '22 08:09

Paresh Navadiya