1

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?

openfrog
  • 40,201
  • 65
  • 225
  • 373

2 Answers2

4

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];
}
Aidan Steele
  • 10,999
  • 6
  • 38
  • 59
0

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
  • 85,404
  • 22
  • 176
  • 172