适用于iPad的通用应用无法加载iPad .xib文件?

Sim*_*iwi 6 xib universal ipad ios

我一直试图弄清楚为什么会这样,但似乎在我的通用应用程序的iPad版本中,它正在加载iPhone .xib而不是iPad.

我用@ iphone.xib的后缀命名我的iPhone xibs,然后用.xib留下我的iPad.我读过这样做是因为有人说这对他们有用,但在我的情况下它对我不起作用!

即使我为不同的.xib文件做~ipad.xib和~iphone.xib,它仍然会加载iPhone版本!

**有没有办法完全确认它是在加载iPhone版本而不是iPad版本?

有没有办法解决这个问题,以便iPad加载iPad .xibs?**

谢谢!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

// Override point for customization after application launch.
    self.viewController = [[[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

Dom*_*adl 4

在我的应用程序中,我这样做。我为 iPad 视图创建单独的 .h、.m 和 XIB 文件,然后在 AppDelegate 中我简单地创建一个 if 条件,该条件决定它将显示哪个视图控制器。
顺便提一句。我不在 XIB 上使用这些后缀,而是按照我想要的方式命名它们。

我的 AppDelegate.h 文件(其中一部分)

 @class FirstViewController;
 @class FirstIpadViewController;    
 .......
 .......
 @property (nonatomic, retain) IBOutlet FirstViewController *viewController;
 @property (nonatomic, retain) IBOutlet FirstIpadViewController *ipadViewController;
Run Code Online (Sandbox Code Playgroud)

我的 AppDelegate.m 文件(其中一部分)

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
} else {
    self.window.rootViewController = self.ipadViewController;
    [self.window makeKeyAndVisible];
}
Run Code Online (Sandbox Code Playgroud)

这绝对应该做到。只需将 .h 文件中的类和属性更改为您的视图控制器,您就可以开始了:)

编辑

我刚刚知道如何去做。正确的命名约定是 _iPhone 和 iPad。这与我上面发布的基本相同,唯一的变化是它将具有相同的 .h 和 .m 文件,但 XIB 不同。

在 AppDelegate .m 文件中

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
    } else {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)