1个viewController怎么关联2个XIB,一个是iphone的XIB,一个是ipad的xib
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
YourViewController *vc = [[[YourViewController alloc] initWithNibName:@"YourViewController_iPhone" bundle:nil] autorelease];
}
else
{
YourViewController *vc = [[[YourViewController alloc] initWithNibName:@"YourViewController_iPad" bundle:nil] autorelease];
}
Nib names that include a platform-specific identifier such as ~iphone or ~ipad are loaded only on a device of the corresponding type. For example, a nib name of MyViewController~ipad.nib is loaded only on iPad. If your app supports both platform types, you must provide versions of your nib files for each platform.
即准备2个XIB
文件,文件名中使用不同的后缀(~iphone
/~ipad
):
YourViewControlle~iphone.xib
YourViewControlle~ipad.xib
应用代码用统一的一行:
YourViewController *vc = [[[YourViewController alloc] initWithNibName:nil bundle:nil] autorelease];
因为是参数都是空,在有ARC
的Objective-C
下,上面的代码可以写成:
YourViewController *vc = [YourViewController new];
试试看~