userInterfaceIdiom always indicate iPhone

前端 未结 2 1994
失恋的感觉
失恋的感觉 2021-01-20 05:16

I added the following code to AppDelegate:

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    self.viewController = [[View         


        
2条回答
  •  青春惊慌失措
    2021-01-20 05:51

    Use this

    #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");
    }
    

提交回复
热议问题