简体   繁体   中英

Iphone View explanation in detail (View, Superview, etc)

I'm looking for an in-depth breakdown/explanation of the iphone's view usage. Like, what controllers have what types of views, how they relate (child <> parent), how they can be nested, added and removed, etc.

Preferably something with some pictures would be nice too (I'm a visual learner).

But yeah, in-depth, technical, explanations of the iphone view system when used in IB/Obj-c would be awesome.

Also, feel free to give your breakdown or post to resources and I'll do the research.

Thanks

EDIT:

  • Ok, I'll be more specific. Is the View a stack - is it a queue? What does it look like when I call addtosubview?

  • What happens if the view isn't a full UIView, but say a smaller UI Control - will it be visible?

  • Say I have a UIView with a UITabView (2 items) and one content view is a UITtableView. What's the parent view? What is the order of the children? Is that all dependent on how I add them to the view? In this case, the UITabBar control takes care of handling the views when I select the button.

  • When I call insertSubview how do I know what index to position it at?

This will be a good place to start (go from here to UIViewController and others that seem relevant). A UIView can contain many subviews of any type (they all inherit from UIView). To nest views, you add the subview to the superview [superview addSubview:subview] . You should also read up on Model-View-Controller .

Edit: This SO question might also shed some light on the matter.

Edit edit: Best I can do to answer your questions:

  1. UIViews have an iVar subviews which is an array of subviews. Each of these also has such an array and can contain UIViews.

  2. I assume you mean not full screen, generally, the topmost view is a UIWindow, and to this you add any UIView subclass you like, such as UISlider.

  3. Your UIView has a subview UITabView, I don't know specifically, but I would guess it has two subviews, one of which is visible at a time, and one of these is the UITableView. Order is dependent on the order you add them in, and they will overlap each other depending on this order, but it can be changed with sendSubviewToBack and bringSubviewToFront.

  4. If you want a specific view order, you're probably better off using insertSubview:aboveSubview: and the equivalent below, rather than at index.

Hope some of this helps.

Ok, I'll be more specific. Is the View a stack - is it a queue? What does it look like when I call addtosubview?

I like to think of it as a tree. The window is the root node, and it has any number of subviews. Those subviews can have any number of their own subviews, going down as far as necessary to create the full interface. The addSubview and removeFromSubview methods manipulate a view's "children".

What happens if the view isn't a full UIView, but say a smaller UI Control - will it be visible?

My understanding is that everything on the screen is a subclass of UIView , even the UIControl objects. Therefore, they behave mostly the same.

Say I have a UIView with a UITabView (2 items) and one content view is a UITtableView. What's the parent view? What is the order of the children? Is that all dependent on how I add them to the view? In this case, the UITabBar control takes care of handling the views when I select the button.

I'm not sure: David's answer has more info that should help.

When I call insertSubview how do I know what index to position it at?

I wouldn't worry about it: most of the time you just want addSubview and you won't care about the internal order.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM