Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isBeingPresented value is inconsistent

I present a NavigationController with a ViewController in it modally.

In the ViewController I can see that self.navigationController.isBeingPresented is true.

But if I now push a new ViewController on the modally presented NavigationController and pop back to the original ViewController the same call to check isBeingPresented returns false.

Documentation is sparse but I can't really explain this inconsistency other than that it may be a bug?

like image 971
Alper Avatar asked Jan 23 '18 12:01

Alper


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.

What is the role of UIViewController?

The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.

What is a Viewcontroller IOS?

A view controller acts as an intermediary between the views it manages and the data of your app. The methods and properties of the UIViewController class let you manage the visual presentation of your app. When you subclass UIViewController , you add any variables you need to manage your data in your subclass.

What is presentedViewController Swift?

In Apple's developer documentation, the property presentedViewController in UIViewController is described as "The view controller that is presented by this view controller, or one of its ancestors in the view controller hierarchy".


1 Answers

That's the intended behavior. isBeingPresented is true only when the given viewController is currently being presented (docs):

A Boolean value indicating whether the view controller is being presented.

and not when it is already presented. It is set to true during the presentation process - from the point when navigation to that view controller starts until the moment when the view controller is fully presented, and all the lifecycle events happened (presentation animations finished, viewWillAppear/viewDidAppear callbacks were called, etc.). After that moment, the view controller is presented, but not is being presented, thus the isBeingPresented will not be set to true anymore.

The self.navigationController was presented at first (by modal presentation), popping a view controller from it does not trigger a presentation. After presenting a UINavigationController, it is presented whole time during pushing and popping view controllers on it. You would have to dismiss the navigationController, and then present it again for the isBeingPresented to be true - because only during modal presentation it is being presented.

like image 195
Milan Nosáľ Avatar answered Oct 16 '22 10:10

Milan Nosáľ