Cocoa (Touch) for Swing Developers #1: Where Are the Layouts?
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
(likeadd
in Swing)?
These are just two concrete questions tha开发者_JS百科t I've thought of just now, but I would love to see any translation of Swing concepts to Cocoa Touch.
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.
- 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.
- Yes, you are completely right.
精彩评论