作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我设置了一个名为 isUsingiPad
的 BOOL
来检测我的用户何时使用 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/
我是一名优秀的程序员,十分优秀!