Trouble understanding universal apps, multiple view controllers and xib files
I'm trying to figure out the best way to approach writing a universal app (iPhone/iPad)...mostly concerning how to handle multiple view controllers and their xib files.
When 开发者_开发百科I start with a window-based app template, Xcode 4 gives me: - AppDelegate - iPhone AppDelegate & xib file - iPad AppDelegate & xib file
I get the idea of the separate xib files, but what I really want to do is add some view controllers with a xib for iPhone & iPad...but I really don't understand where to put what...what to overload, what to connect to what, etc..
I want to keep it as simple as possible.
Thanks!
What I do (if the view controller can easily be used for both) is create the appropriate files like so.
MyViewController.h
MyViewController.m
MyViewController~ipad.xib
MyViewController~iphone.xib
Set the File's Owner
in both the xib
files to your UIViewController
subclass and connect up the view + anything else you want connected.
When I init my view controller this is all that's required
MyViewController *viewController = [[MyViewController alloc] init];
// OR
MyViewController *viewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
The Apple docs for UIViewController state that if you provide a xib with the same name as the view controller it will be loaded. The ~ipad
and ~iphone
ensure that the correct xib is loaded.
精彩评论