适用于iPad的通用应用无法加载iPad .xib文件? [英] Universal app for iPad not loading iPad .xib files?

查看:91
本文介绍了适用于iPad的通用应用无法加载iPad .xib文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been trying to figure out why this has been happening but it seems that, in the iPad version of my universal app, it is loading the iPhone .xib instead of the iPad one.

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

I have named my iPhone xibs with a suffix of ~iphone.xib and I left my iPad ones just with .xib . I read to do that because someone said that worked for them but in my case it did not work for me!

即使我做了~ipo.xib和~iphone。 xib用于不同的.xib文件,它仍然加载iPhone版本!

Even if I do ~ipad.xib and ~iphone.xib for the different .xib files, it still loads the iPhone version!

* *有没有办法完全确认它是在加载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;
}


推荐答案

在我的应用程序中,我做就像这样。我为iPad视图创建单独的.h,.m和XIB文件,然后在AppDelegate中我只创建一个if条件,它决定它将显示哪个视图控制器。

顺便说一句。我不在XIB上使用这些后缀,我将它们命名为我想要的。

In my app, I do it like this. I create separate .h, .m and XIB files for iPad views and then in AppDelegate I simply make an if condition, which decides which view controller it will show.
Btw. I don't use those suffixes on XIBs, I name them to what I want to.

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

My AppDelegate.h file (a part of it)

 @class FirstViewController;
 @class FirstIpadViewController;    
 .......
 .......
 @property (nonatomic, retain) IBOutlet FirstViewController *viewController;
 @property (nonatomic, retain) IBOutlet FirstIpadViewController *ipadViewController;

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

My AppDelegate.m file (a part of it)

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
} else {
    self.window.rootViewController = self.ipadViewController;
    [self.window makeKeyAndVisible];
}

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

This should definitely do it. Just change the class and the property in .h file, to your view controller and you should be good to go :)

编辑

我刚刚发现了如何做到这一点。正确的命名约定是_iPhone和iPad。这与我上面发布的基本相同,只是更改是它将具有相同的.h和.m文件,但是不同的XIB。

I have just found out how to do it. And the proper naming conventions are _iPhone and iPad. This is basically the same as I posted above, only change is that it will have the same .h and .m files, but different XIBs.

在AppDelegate .m文件中

In the AppDelegate .m file

    - (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;
}

这篇关于适用于iPad的通用应用无法加载iPad .xib文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆