我有完整的代码在视图控制器。所以,我需要在iPad,iPhone和iPod中显示相同的输出。所以,我使用单视图控制器处理数据。为此,我如何选择不同的XIB,可能ipod或ipad依赖于当前设备在iOS?
而不是创建一个视图控制器,我想要一个视图控制器和2 XIB的这是非常简单的,当你创建一个通用的应用程序,它本身会给代码检查设备类型和加载特定的xib。
例如
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];
}
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];
}
[UIDevice currentDevice]
将给出当前设备的详细信息。在if循环中使用它,并选择iPhone或I pad的xib。
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
load 1 xib
}
else
{
load another
}