本文介绍了如何为单个类加载不同的xib取决于iOS中的当前设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图控制器中有完整的代码。所以,我需要在iPad,iPhone和iPod上显示相同的输出。因此,我使用单视图控制器来处理数据。为此目的,如何选择可能ipod或ipad取决于iOS中当前设备的不同XIB?

I have the complete code in view controller. So, i need to display the same output in iPad,iPhone and iPod. So, am using single view controller for processing data.For this purpose how can i select the different XIB that may ipod or ipad depends on current device in iOS?

而不是creatimg一个视图控制器我想要单个viewcontroller和2个XIB

Instead of creatimg one more view controllers i want single viewcontroller and 2 XIB's

推荐答案

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];
}

这篇关于如何为单个类加载不同的xib取决于iOS中的当前设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 19:36