openfrog
openfrog

Reputation: 40735

How to provide separate classes for iPhone + iPad in one universal build?

Problem: In my iPhone app code, I'm positioning and animating a lot of views programmatically. For the iPad, I want to provide a completely different user interface, but also programmatically. I don't like to use Xib files. How can I make different views and view controllers and load these depending on if it's an iPad or an iPhone? What's the cleanest way?

Upvotes: 0

Views: 118

Answers (2)

Ben
Ben

Reputation: 2992

In addition, if you are having compilation problems because you are programatically creating classes only available to iOS 3.2 and above you can use code like this:

Class popClass = NSClassFromString(@"UIPopoverController");
if(popClass) {
    id infoPop = [[popClass alloc] initWithContentViewController:popViewController];
    [infoPop presentPopoverFromRect:CGRectMake(20, 70, 10, 10) inView:self.view permittedArrowDirections:4 animated:YES];
}

Upvotes: 1

Jeroen de Leeuw
Jeroen de Leeuw

Reputation: 907

You just have to specify the device identifier, you can do that by adding the string "~iphone" or "~ipad". So for a view controller this would be; "MyViewController~iphone.m" and for the iPad "MyViewController~ipad.m"

Upvotes: 2

Related Questions