How does the overall view hierarchy change when using UIKit view manipulations?

Posted by executor21 on Stack Overflow See other posts from Stack Overflow or by executor21
Published on 2010-03-18T22:40:08Z Indexed on 2010/03/18 22:41 UTC
Read the original article Hit count: 343

I've been trying to figure out what happens in the view hierarchy when methods like pushViewController:animated, presentModalViewController:animated, and tab switches in UITabBarViewController are used, as well as UIAlertView and UIActionSheet.

(Side note: I'm doing this because I need to know whether a specific UIView of my creation is visible on screen when I do not know anything about how it or its superview may have been added to the view hierarchy. If someone knows a good way to determine this, I'd welcome the knowledge.)

To figure it out, I've been logging out the hierarchy of [[UIApplication sharedApplication] keyWindow] subviews in different circumstances. Is the following correct:

  1. When a new viewController is pushed onto the stack of a UINavigationController, the old viewController's view is no longer in the view hierarchy. That is, only the top view controller's view is a subview of UINavigationController's view (according to logs, it's actually several private classes such as UILayoutContainerView). Are the views of view controllers below the top controller of the stack actually removed from the window?

  2. A very similar thing happens when a new viewController is presented via presentModalViewController:animated. The new viewController's view is the only subview of the kew window. Is this correct?

  3. The easiest thing to understand: a UIAlertView creates its own window and makes it key.

  4. The strangest thing I encountered: a UIActionSheet is shown via showInView: method, the actionSheet isn't in the view hierarchy at all. It's not a subview of the view passed as an argument to showInView:, it isn't added as a subview of the key window, and it doesn't create its own window. How does it appear, then?

  5. I haven't tried this yet, so I'd like to know what happens in the keyWindow hierarchy when tabs in a UITabBarController are switched. Is the view of the selected UIViewController moved to the top, or does it work like with pushViewController:animated and presentModalViewController:animated, where only the displayed view is in the window hierarchy?

© Stack Overflow or respective owner

Related posts about uiviewcontroller

Related posts about uinavigationcontroller