我如何加载单个类的不同xibs取决于当前设备在iOS?

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

而不是creatimg一个更多的视图控制器我想要单个viewcontroller和2个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]; } 

这是非常简单的,当你创build一个通用的应用程序,它会给代码检查设备types和加载特定的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]; } 

[UIDevice currentDevice]会给你关于当前设备的细节。 在if循环中使用这个,并selectiphone或i pad的xib。

  if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { load 1 xib } else { load another }