簡體   English   中英

適用於通用iOS 6應用的程序化情節提要

[英]programmatic storyboard for universal iOS 6 app

更新1

屬性檢查器

更新1

更新0

當我實現提供的答案中建議的代碼時,執行中止

更新0

這個很好的問題和答案與我的同時具有iPhone和iPad Xibs且現在希望使用情節提要的Universal應用程序不太相稱。

這是基於xib的BSAppDelegate.m(在情節提要之前)

    #import "BSAppDelegate.h"
    #import "BSViewController.h"

    @implementation BSAppDelegate

    NSString *receivedData;

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        // return YES;
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            self.viewController = [[BSViewController alloc] initWithNibName:@"BSViewController_iPhone" bundle:nil];
        } else {        
            self.viewController = [[BSViewController alloc] initWithNibName:@"BSViewController_iPad" bundle:nil];
    }
        self.window.rootViewController = self.viewController;   
        [self.window makeKeyAndVisible];
        return YES;
    }

我試圖在上面的else之后插入以下代碼,但是我不能完全完成需要將self.viewController設置為與上述代碼兼容的代碼修復。

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"BSViewController"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];

您能告訴我如何修改代碼嗎? 我正在使用Xcode 4.5.2並為iOS 6開發。

兩個問題:

  1. 只需將self.ViewController設置為您從情節提要中獲取的vc :)

      #import "BSAppDelegate.h" #import "BSViewController.h" @implementation BSAppDelegate NSString *receivedData; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // return YES; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { self.viewController = [[BSViewController alloc] initWithNibName:@"BSViewController_iPhone" bundle:nil]; } else { UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil]; UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"BSViewController"]; vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; self.viewController = (id)vc; } self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; } 
  2. 在情節提要中,沒有設置名為“ BSViewController”的標識符,因此調用InstantiateViewControllerWithIdentifier將會失敗。 設置在屏幕快照中可見的標識符(又稱為情節提要ID)

暫無
暫無

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

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