Cocoa touch - create a view template for iPad
This is a difficult question to describe.
I am just starting to make an iPad app.
Now that I have the amount of properties I have, I plan on having different but similar "looks" to fill the space. (it might be easier to think of a newspaper site where many of the columns are similar)
I would like to create a "view template" so that I can reuse the view in different places.
Can I create a view template in Interface Builder? (which means I design the UIView in Interface Builder and then somehow I can just do [window addSubview: viewController.viewTemplate1]; multiple times?
If so, how can I load this view template in different places?
If you know example code / tutorial that does something like this, this would work too.
Thanks
Tee
a source to share
Strictly speaking, UIViewController
s, as Laurent suggested, are only for views that take up the entire screen. From View Controller Programming Guide :
The individual correspondence between the view controller and the screen is a very important aspect when developing your application. You shouldn't use multiple custom view controllers to control different parts of the same screen.
The correct technique here is to use a method NSBundle
-loadNibNamed:owner:options:
that creates the contents of the NIB and returns an array of top-level objects. In that case, for each of your views, you would do something like this:
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"MyViewTemplate" owner:nil options:nil];
UIView *newView = [nibObjects objectAtIndex:0];
[myViews addObject:newView];
// set up the view and add it to your content view and so on
a source to share
The easiest way is to create an XIB file with: - The view template you want. - A subclass of UIViewController that will act as the File Owner. - bind UIView to a subclass of UIViewController.
With this method (which is widely used in Apple samples), you can download as many as you want and place them wherever you want.
a source to share