プロジェクトでmain.m
あなたは次のようなことができます
int main(int argc, char *argv[])
{
@autoreleasepool {
NSString *appDelegateName;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
appDelegateName = NSStringFromClass([AppDelegateIPhone class]);
} else {
appDelegateName = NSStringFromClass([AppDelegateIPad class]);
}
return UIApplicationMain(argc, argv, nil, appDelegateName);
}
}
しかし、IMOはそうすべきではありません。
代わりに、Apple が行うように、アプリ デリゲートで異なるビュー コントローラーまたは異なる XIB をロードします。
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
} else {
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
@end