在ios中检查屏幕上的当前视图控制器

时间:2020-12-18 07:03:06

I have presented a UINavigationController containing UIViewController on self object with following code

我在自我对象上展示了一个包含UIViewController的UINavigationController,其代码如下

  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

但是在第二次调用上面的代码之前,我想知道屏幕上出现的当前视图控制器是否是drawController。我正在使用以下代码

    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.

但它不适合我,也适用于iOS 5.0,所以我被困在这里。请帮助我知道我应该怎么知道屏幕上出现的当前UIViewController是哪个类以及drawContoller是否仍然出现在屏幕上?对不起我的错字错误,如果有的话。任何帮助将不胜感激。

Thanks Neha Mehta

谢谢Neha Mehta

3 个解决方案

#1


5  

Not the prettiest code, but this should work:

不是最漂亮的代码,但这应该工作:

if ([self.presentedViewController isKindOfClass:[UINavigationController class]] &&
   ((UINavigationController *)self.presentedViewController).topViewController == drawController) {
   …

#2


22  

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

使用navigationController的visibleViewController属性和isKindOfClass方法来了解最重要的事情:

if([self.navigationController.visibleViewController isKindOfClass:[yourcontroller class]])
   //exists
else
   //not exists

#3


3  

Check for UINavigationControllers visibleViewController method.

检查UINavigationControllers visibleViewController方法。

For documentation, please see UINavigationController

有关文档,请参阅UINavigationController

#1


5  

Not the prettiest code, but this should work:

不是最漂亮的代码,但这应该工作:

if ([self.presentedViewController isKindOfClass:[UINavigationController class]] &&
   ((UINavigationController *)self.presentedViewController).topViewController == drawController) {
   …

#2


22  

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

使用navigationController的visibleViewController属性和isKindOfClass方法来了解最重要的事情:

if([self.navigationController.visibleViewController isKindOfClass:[yourcontroller class]])
   //exists
else
   //not exists

#3


3  

Check for UINavigationControllers visibleViewController method.

检查UINavigationControllers visibleViewController方法。

For documentation, please see UINavigationController

有关文档,请参阅UINavigationController