userInterfaceIdiom总是指示iPhone
我将下面的代码添加到AppDelegate中:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; NSLog(@"iPhone found"); } else { self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; NSLog(@"iPad found"); }
在iPad 2上运行时,userInterfaceIdiom始终等于UIUserInterfaceIdiomPhone。我的iPad 2在iOS 6.1.3上运行。
我找不出什么问题。
任何帮助表示赞赏!
提前致谢!
目标设备应该是通用的 ,
用这个
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) if (!IS_IPAD) { self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; NSLog(@"iPhone found"); } else { self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; NSLog(@"iPad found"); }