我按照一些教程在应用程序启动期间创建了一个打开的门动画,但它调用了一个
xib文件和我想调用故事板,但我没有足够的经验。这是我的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[OpenDoorsViewController alloc] initWithNibName:@"OpenDoorsViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}发布于 2013-04-10 01:21:06
如果您只是想在应用程序启动时加载故事板的初始视图控制器,只需在application:didFinishLaunchingWithOptions:中返回YES即可。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}如果您想要从storyboard加载特定的控制器,您需要首先通过以下方式获取storybard实例
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"StoryboardName" bundle:nil];然后使用它来实例化所需的控制器
UIViewController * controller = [storyboard instantiateViewControllerWithIdentifier:@"controllerIdentifier"];其中controllerIdentifier已被指定为界面生成器中控制器的情节提要标识符。
下面是一个加载特定视图控制器的示例,在启动时呈现它。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"StoryboardName" bundle:nil];
UIViewController * controller = [storyboard instantiateViewControllerWithIdentifier:@"controllerIdentifier"];
self.window.rootViewController = controller;
return YES;
}发布于 2013-04-10 01:16:06
如果你开始一个新的iOS项目并选择“使用故事板”,故事板将自动为你预加载。
Storyboard是一个包含应用程序的所有控制器(场景)的地方,要引用一个控制器(场景),您需要使用
UIViewController *controller = [[UIStoryboard storyboardWithName:@"storyboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"an identifier"];https://stackoverflow.com/questions/15908080
复制相似问题