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

前端 未结 7 677
臣服心动
臣服心动 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:08

    You need to check if your viewcontroller is on top of the stack of navigationcontroller's viewcontroller array. A sample code is,

    if (self.navigationController.topViewController == self) {
        //the view is currently displayed
    }
    

    You can use this inside the viewWillAppear method to check whether the current view is visible.

提交回复
热议问题