views:

477

answers:

2

Hey,

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?

+3  A: 

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.

David Kanarek
Im familiar with the methods (addSubview, removeFromSubview) - and I'm very familiar with MVC. I guess I need to edit my question to be more specific.
Mr-sk
I'll read the first link, since I've not seen it before. And heh, yeah I've seen the UIView documentation, but I'll give it a good read.I'm more interested in the structure behind the scene of the views and how they are managed/treated.
Mr-sk
Sorry, I kinda read that as new to iPhone development. What exactly is troubling you?
David Kanarek
I updated my OP.
Mr-sk
Thanks - I guess I just gotta keep reading and playing around.
Mr-sk
+3  A: 

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.

Justin Voss
Cool, thanks for the additional info (+1). Appreciate it.
Mr-sk