繁体   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