0

更新 1

属性インスペクター

更新 1

更新 0

提供された回答で提案されたコードを実装すると、実行が中止されます.

更新 0

この素晴らしい質問と回答は、iPhone と iPad の両方の xib を持っていて、ストーリーボードを使用したいという私の 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 向けに開発しています。

4

1 に答える 1

0

2 つの問題:

  1. ストーリーボードから取得した vc に self.ViewController を設定するだけです:)

        #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) を設定します

于 2013-02-17T15:28:21.110 に答える