[英]programmatic storyboard for universal iOS 6 app
update 1 更新1
update 1 更新1
update 0 更新0
.
。
update 0 更新0
This fine question and answer does not quite deal with my Universal app which had both a iPhone and iPad xibs and now wants to use a storyboard. 这个很好的问题和答案与我的同时具有iPhone和iPad Xibs且现在希望使用情节提要的Universal应用程序不太相称。
This is the xib based BSAppDelegate.m (before storyboard) 这是基于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;
}
I have tried to insert the following code right after the else
above but I cannot quite complete the code fix which needs to set self.viewController
to be compatible with the above code. 我试图在上面的
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];
Can you show me how to fix my code, please? 您能告诉我如何修改代码吗? I am using Xcode 4.5.2 and developing for iOS 6.
我正在使用Xcode 4.5.2并为iOS 6开发。
two issues: 两个问题:
just set self.ViewController to your vc which you get from the storyboard :) 只需将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; }
in your storyboard, you have no identifier named 'BSViewController' set so the call instantiateViewControllerWithIdentifier will fail. 在情节提要中,没有设置名为“ BSViewController”的标识符,因此调用InstantiateViewControllerWithIdentifier将会失败。 set the identifier (aka the Storyboard ID) visible in your screenshot
设置在屏幕快照中可见的标识符(又称为情节提要ID)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.