0

更新 1

属性检查器

更新 1

更新 0

当我实现提供的答案中建议的代码时,执行中止.

更新 0

这个很好的问题和答案并不完全适用于我的通用应用程序,它同时具有 iPhone 和 iPad xibs,现在想要使用情节提要。

这是基于 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

两个问题:

  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 将失败。设置在屏幕截图中可见的标识符(又名 Storyboard ID)

于 2013-02-17T15:28:21.110 回答