簡體   English   中英

將iPad故事板添加到現有的iPhone項目

[英]Add iPad storyboard to existing iphone project

我僅為iPhone / iPod用戶創建了項目。 現在我想使它也適用於ipad用戶。 我有2個故事板; 3.5英寸和4英寸。

這是我的步驟:

1)我創建了一個新的故事板。 文件-新文件-用戶界面-Storyboard for iPad。

2)我將目標設備從iPhone更改為通用設備。

3)我在iPad部署信息部分中設置了主故事板。

4)最后,我將所有內容復制到4英寸iphone的情節提要上,並將其粘貼到新的ipad情節提要上。 (我沒有更改任何內容,包括屏幕尺寸)

我試圖在新的故事板上僅放置一個視圖控制器,但結果是相同的。

然后,我在iPad模擬器上運行並構建了我的應用程序。 我在下面得到一個錯誤:

2013-07-28 19:02:42.151 Test[40038:12203] *** Terminating app due to uncaught 
exception 'NSInvalidArgumentException', reason: '-[ViewController topViewController]: 
unrecognized selector sent to instance 0x7888940'
*** First throw call stack:
(0x1b02012 0x1573e7e 0x1b8d4bd 0x1af1bbc 0x1af194e 0x252b 0x2626 0x4b5157 0x4b5747   
0x4b694b 0x4c7cb5 0x4c8beb 0x4ba698 0x194cdf9 0x194cad0 0x1a77bf5 0x1a77962 0x1aa8bb6 
0x1aa7f44 0x1aa7e1b 0x4b617a 0x4b7ffc 0x1d5d 0x1c85)
libc++abi.dylib: terminate called throwing an exception

這是在AppDelegate.m中

-(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:@"MainStoryboard" 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;

}
}

誰能解釋什么地方不對?

拆分視圖控制器中的最后一個對象不是UINavigationController。 檢查您的情節提要。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM