gpt4 book ai didi

ios - 在通用应用程序中加载 iPad Nib

转载 作者:行者123 更新时间:2023-12-04 13:23:28 25 4
gpt4 key购买 nike

我设置了一个名为 isUsingiPadBOOL 来检测我的用户何时使用 iPad。我用它来这样做:

UIDevice* userDevice = [UIDevice currentDevice];
if (userDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
isUsingiPad = YES;
}

当我的应用程序首次启动时,它会检查正在使用的设备是否已通过我的注册。如果有,它会将用户发送到我的应用程序的主视图 Controller 。但是......当注册用户(使用 iPad)注册、关闭应用程序,然后重新打开它时,它们将被发送到 iPhone nib 而不是 iPad。我的应用程序中的每个 View 都有 2 个 Nib 。一个用于 iPhone,一个用于 iPad。有一个 View Controller 控制每组 2 个。我已经放置了代码来处理它是 iPhone 还是 iPad。我的问题是:我应该添加什么来确保用户每次都能使用 iPad Nib ?我在哪里添加这个?我可以编辑这个问题以包含任何必要的代码。提前致谢。

编辑:更新了 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: 方法。

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


self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

UIDevice* userDevice = [UIDevice currentDevice];
if (userDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
isUsingiPad = YES;
}

if (!isUsingiPad) {
self.viewController= [[PassportAmericaViewController alloc] initWithNibName:@"PassportAmericaViewController" bundle:nil];
} else {
self.viewController = [[PassportAmericaViewController alloc] initWithNibName:@"PassportAmericaViewController-iPad" bundle:nil];
}

self.window.rootViewController = self.viewController;

[self.window addSubview:navigationController.view];

[self.window makeKeyAndVisible];

return YES;
}

最佳答案

这就是 Apple 在应用程序模板中使用的方法,它在您的 AppDelegates 中实现。 applicationDidFinishLaunchingWithOptions :

现在确保您的用户每次都返回到正确的屏幕,这取决于您的设置,您可能希望在 viewDidLoad 中对其进行初始化或 viewDidAppear .

 - (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 Nib ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10000651/

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