Presenting view controllers

I am building an app using a tab bar view controller. What happens is as follows.

  1. I presented a view controller modally over a current context. I used present(_:animated:completion:) with the property modalPresentationStyle set to currentContext
  2. I selected a different tab bar item.
  3. I came back to the original tab bar item. So I saw the view controller presented in Step 1.
  4. I dismissed the view controller and got a black screen.

It seems that the instance method present(_:animated:completion:) is dedicated to the case wherein the user comes back directly to the presenting view controller. So I guess I am supposed to disable any options that send a user to a different scene.

Another resolution would be using a navigation controller. I wondered whether I need to put additional navigation controllers to build a stack of view controllers, but it was not the case. I just need to use the method pushViewController(_:animated:) of an instance of UINavigationController. So I only need one navigation controller. Once I used pushViewController(_:animated:), I can dismiss the view controller by popping or popViewController(animated:). In fact, there are two other options: popToRootViewController(animated:) and popToViewController(_:animated:).

The following page is very helpful here: Pushing, Popping, Presenting, & Dismissing ViewControllers

I also checked Wikepedia. It says:
Users must interact with the modal window before they can return the parent application.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s