gpt4 book ai didi

iphone - 为 iphone 4 和 5 创建单独的 Storyboard

转载 作者:行者123 更新时间:2023-11-29 13:07:51 25 4
gpt4 key购买 nike

我正在尝试创建 2 个 Storyboard,一个用于 iPhone 4,一个用于 iPhone 5。我希望在启动时检测到用户正在使用的设备。我使用了以下代码并在我的应用程序 delegate.m 中实现了它,但收到错误:

Use of undeclared identifier "initializeStoryBoardBasedOnScreenSize"

这是我使用的代码:

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


-(void)initializeStoryBoardBasedOnScreenSize {

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{ // The iOS device = iPhone or iPod Touch


CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

if (iOSDeviceScreenSize.height == 480)
{ // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)

// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone35" bundle:nil];

// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [iPhone35Storyboard instantiateInitialViewController];

// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = initialViewController;

// Set the window object to be the key window and show it
[self.window makeKeyAndVisible];
}

if (iOSDeviceScreenSize.height == 568)
{ // iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured)

// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4" bundle:nil];

// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];

// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = initialViewController;

// Set the window object to be the key window and show it
[self.window makeKeyAndVisible];
}

} else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)

{ // The iOS device = iPad

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;

}

我可能需要导入一些东西来修复错误吗?

最佳答案

您已尝试在 application:didFinishLaunchingWithOptions:定义一个方法:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
-(void)initializeStoryBoardBasedOnScreenSize {
// ... your code ...
}
return YES;
}

这不是您想要的,顺便说一句。不支持嵌套函数(或方法)在 Objective-C 中。

您的意思可能是定义一个方法并调用它里面 application:didFinishLaunchingWithOptions::

-(void)initializeStoryBoardBasedOnScreenSize {
// ... your code ...
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self initializeStoryBoardBasedOnScreenSize];
return YES;
}

关于iphone - 为 iphone 4 和 5 创建单独的 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18183670/

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