I'm trying to do the basics steps of creating a universal (iphone/ipad) app in Xcode 4. I don't want to be using INterface Builder, if possible, and I want to get away from the cumbersome if statements:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
I create a "window-based project" to get the Universal template that Apple provides. This gives me the three app delegates, with the iPhone and iPad having their own XIBs, inside their specific folders.
I would now like to add a view controller, so I create a master "MasterViewController", and two subclassed versions "MasterViewController_iPhone" and "MasterViewController_iPad". I do not create XIBs with any of these. (Do I need to?)
Here is where I get confused. In the master app delegate, I place the code
[self.window makeKeyAndVisible];
I don't add any other code, allowing the sub-classed app delegates to instantiate their respective view controllers. For example, in the iphone app delegate I place:
myVC_iPhone = [[MasterViewController_iPhone alloc] initWithNibName:nil bundle:nil];
[self.window addSubview: myVC_iPhone];
But this gives me the error:
Incompatible pointer types sending 'MasterViewController_iPhone *' to parameter of type 'UIView *'
I'm missing something basic here. Perhaps my naming conventions are wrong; perhaps makeKeyAndVisible shouldn't be in the master app delegate; perhaps I need XIBs for each view controller. Can anyone push me along here? Thanks!
addSubview:
takes an UIView as parameter not the view controller surrounding it. You should be fine using [self.window addSubview: myVC_iPhone.view];
.