views:

10

answers:

2

I have a special class that manages gestures and other things. It is strongly targeted towards iPhone. On the iPad, I need a 90% different behavior of that class, so I want to split MyController into MyController_iPhone and MyController_iPad.

How would I alloc-init the appropriate class depending on if it's the iPad or iPhone?

+1  A: 

You can do something along the following lines:

MyController *controller = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    controller = [[MyController_iPad alloc] init];
} else {
    controller = [[MyController_iPhone alloc] init];
}
Sedate Alien
A: 

You might want to subclass the controller for, say, the iPad. When you push/present it, check to see which platform you're on, and if you're on iPad, present the iPad subclass, with the modified behavior. You can use the UI_USER_INTERFACE_IDIOM() macro determine which device you're on.

Ben Gottlieb