userInterfaceIdiom始终指示iPhone

时间:2013-05-01 14:10:56

标签: ios

我将以下代码添加到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上运行。

我无法找出问题所在。

感谢任何帮助!

提前致谢!

2 个答案:

答案 0 :(得分:6)

目标设备应通用

enter image description here

答案 1 :(得分:0)

使用此

#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");
}
相关问题