gpt4 book ai didi

ios - iPad 的通用应用程序无法加载 iPad .xib 文件?

转载 作者:可可西里 更新时间:2023-11-01 03:56:21 25 4
gpt4 key购买 nike

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

我已将我的 iPhone xibs 命名为后缀为 ~iphone.xib ,而我将 iPad 的后缀命名为 .xib 。我阅读是为了这样做,因为有人说这对他们有用,但就我而言,它对我不起作用!

即使我对不同的 .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;
}

最佳答案

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

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

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

我的 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];
}

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

编辑

我刚刚找到了如何去做。正确的命名约定是 _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;
}

关于ios - iPad 的通用应用程序无法加载 iPad .xib 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9753967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com