在项目中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你不应该这样做。
而是像苹果那样做,在应用程序委托中加载不同的视图控制器或不同的 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