简体   繁体   中英

iPhone app converted to iPad app shows iPhone xib not iPad xib

I am in the process of converting an iPhone app to a universal app.

  • I've changed all the xCode settings and added a new MainWindow-iPad.xib
  • I've hooked all the interface builder references up (eg MainWindow-iPad to the appropriate iPad class viewController, window etc)
  • I've added a new iPad class for the opening view controller and declared it in my AppDelegate.h file, and synthesized them in my AppDelegate.m file:

    UIWindow *window; UIWindow *windowiPad; AppViewController *viewController; AppViewControlleriPad *viewControlleriPad;

  • in the app delegate I check for which device I am running and load the appropriate class:

     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { // Override point for customization after application launch. navController = [[UINavigationController alloc] initWithRootViewController:viewControlleriPad]; // Add the view controller's view to the window and display. [windowiPad addSubview:navController.view]; [windowiPad makeKeyAndVisible]; [navController setNavigationBarHidden:YES animated:NO]; } else { //I am an iPhone! // Override point for customization after application launch. navController = [[UINavigationController alloc] initWithRootViewController:viewController]; // Add the view controller's view to the window and display. [window addSubview:navController.view]; [window makeKeyAndVisible]; [navController setNavigationBarHidden:YES animated:NO]; } 

And everything seems to work fine - except it still loads the iPhone nib/xib file AppViewController.xib instead of AppViewControlleriPad.xib. You're welcome to ask for more information but I can't figure out how to get it to load the AppViewControlleriPad.xib when running an iPad rather than the iPhone/original xib file.

I thought, perhaps naively, that if the xib file has the same name as the class of the view controller then the ViewController would use that as its xib.

How can I fix it so that the correct xib is loaded for the correct device?

You have a spelling mistake - correct sufix for iPad resources is "~ipad" instead of "-iPad". With "~ipad" your resources will be loaded automatically depending to device.

And you probably don't need another UIWindow for your iPad controllers. You can use the same window at app starting point. Good practice is also to have one view controller (inside you can perform some special things for different devices) and two nibs (one "normal" and the second one with "~ipad" sufix). In rare cases if whole controller behavior is completely different you may want to use two view controllers.

可能是由于您没有将iPad的视图控制器连接到IB中的文件所有者的原因。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM