1

我按照一些教程在应用程序启动期间创建了一个开门动画,但它正在调用

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;
}
4

2 回答 2

5

如果您只是想在应用程序启动时加载情节提要的初始视图控制器,只需YESapplication:didFinishLaunchingWithOptions:.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    return YES;
}

如果要从情节提要中加载特定的控制器,则需要首先通过以下方式获取情节提要实例

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"StoryboardName" bundle:nil];

然后用它来实例化你需要的控制器

UIViewController * controller = [storyboard instantiateViewControllerWithIdentifier:@"controllerIdentifier"];

其中controllerIdentifier已作为情节提要标识符分配给 Interface Builder 中的控制器。

这是一个加载特定视图控制器的示例,并在启动时显示它。

- (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-09T17:21:06.247 回答
1

如果您开始一个新的 iOS 项目并选择“使用故事板”,故事板将自动为您预加载。

Storyboard 是一个包含应用程序所有控制器(场景)的地方,要引用其中一个,您需要使用

    UIViewController *controller = [[UIStoryboard storyboardWithName:@"storyboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"an identifier"];
于 2013-04-09T17:16:06.380 回答