How do I check if an UIViewController is currently being displayed?

前端 未结 7 678
臣服心动
臣服心动 2021-01-01 16:42

How do I check if an UIViewController is currently being displayed?

My UIViewControllers are listening for NSNotifications - e

7条回答
  •  不知归路
    2021-01-01 17:15

    It's too late to replay on this question.

    To check the instance of a UIViewController is currently on the top of the screen or to check if it is showing on screen, you can put a check like:

    // Get the topmost view showing on the screen as below
        UIViewController * currentVC = ((UINavigationController*)app.window.rootViewController).visibleViewController;
    
    // Now check whether the viewcontroller you want to show is the same as the currently showing view controller.
        if (currentVC.class == myVC.class) {  // Here myVC is any/new instance of the viewcontroller you would like to check or show (if not shown).
             // If both are same then it returns true and executes this block of code.
        }
    

提交回复
热议问题