更新1
更新1
更新0
。
更新0
This fine question and answer与我同时拥有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开发。
答案 0 :(得分:0)
两个问题:
只需将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;
}
,您没有设置名为“BSViewController”的标识符,因此调用instantiateViewControllerWithIdentifier将失败。设置屏幕截图中可见的标识符(又名故事板ID)