views:

118

answers:

2

My iPhone SDK and Objective-C learning is moving ahead quickly, thanks to several great books and online help (including this one). But I do have some basic questions due to what I already know that will be answered eventually, but I'd rather get a heads-up now if possible :)

  • Are there equivalents for LayoutManagers in Cocoa Touch? Are they used, or is absolute positioning used instead? I have seen some of the layout stuff in IB, but I'm not sure what to look at in code.
  • Aside from using the IB, are UIControls added directly to UIView instances using the addSubview (like add in Swing)?

These are just two concrete questions that I've thought of just now, but I would love to see any translation of Swing concepts to Cocoa Touch.

A: 

If you really want to code up an app like it's a website, Three20 is the place to start. The framework provides a URL-based navigator component roughly equivalent to a front controller called TTNavigator.

To directly answer your question about LayoutManager, there is a point where just about everything devolves into creative use of UITableView. It's so customizable and flexible that you can do just about anything. When that breaks down, it's parent UIScrollView is usually a good place to start because it has all the acceleration / bouncing baked-in.

The second question is yes. UIViews are added to UIViews using - (void)addSubview:(UIView *)view. To remove them, use - (void)removeFromSuperview from the child view.

slf
Second and third paragraphs are interesting... why the reference to "code up an app like it's a website?" Just curious, thanks.
Yar
sorry, I probably could have worded that better, I just meant that the navigator makes it more like a centralized action listener
slf
Ok, so about this creative use of the UITableView: isn't that just one column of things in the iPhone version? My question is if I have, for instance, two rows of controls, do I need to code their positioning myself?
Yar
not necessarily, you can create a customized `UITableViewCell` in IB with your designed layout, then load it with `NSBundle` lazily
slf
Okay, I'm going to consider all this and then vote you up/mark you best answer when I actually know what we're talking about :).... thanks!
Yar
A: 
  1. Sadly not, as a result laying out views manually is a real pain. It took me 5 hours to layout a single view just a few days ago. I've considered building aomething like this and releasing it to the masses.
  2. Yes, you are completely right.
Jonathan