1

iPhone 4 用と iPhone 5 用の 2 つのストーリーボードを作成しようとしています。起動時に、ユーザーが使用しているデバイスを検出したいと考えています。次のコードを使用してアプリの 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;

    }

エラーを修正するためにインポートする必要があるものはありますか?

4

2 に答える 2

1

内部でメソッドを定義しようとしました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;
}
于 2013-08-12T09:43:43.720 に答える
0

ここでは単なるエラーかもしれませんが、didFinishApplicationLaunchingWithOptions でアクション void を入力していますか?

このアクション void を使用せずに、すべてを didFinishApplicationLaunchingWithOptions に合わせようとしましたか?

于 2013-08-12T09:48:37.547 に答える