我想使用故事板创建一个名为“child”的视图控制器,所以我定义:
- (TyphoonStoryboard *)storyBoard
{
return [TyphoonDefinition withClass:[TyphoonStoryboard class] configuration:^(TyphoonDefinition* definition) {
[definition useInitializer:@selector(storyboardWithName:factory:bundle:) parameters:^(TyphoonMethod *initializer) {
[initializer injectParameterWith:@"Storyboard"];
[initializer injectParameterWith:self];
[initializer injectParameterWith:[NSBundle mainBundle]];
}];
definition.scope = TyphoonScopeSingleton; //Let's make this a singleton
}];
}
- (ChildViewController *)childViewControllerFromStoryboard
{
return [TyphoonDefinition withFactory:self.storyBoard selector:@selector(instantiateInitialViewController)];
}
我将有一个包含子视图控制器的根视图控制器
- (RootViewController *)rootViewController {
return [TyphoonDefinition withClass:[RootViewController class] configuration:^(TyphoonDefinition *definition) {
[definition useInitializer:@selector(initWithChildViewController:) parameters:^(TyphoonMethod *initializer) {
[initializer injectParameterWith:self.childViewControllerFromStoryboard];
}];
}];
}
最后一部分只是为子视图控制器注入依赖项:
- (ChildViewController *)childViewController {
return [TyphoonDefinition withClass:[ChildViewController class] configuration:^(TyphoonDefinition *definition) {
// Initilization doesn't work.
[definition useInitializer:@selector(initWithData:) parameters:^(TyphoonMethod *initializer) {
[initializer injectParameterWith:self.data];
}];
// Property injection does.
// [definition injectProperty:@selector(data)]
}];
}
超级正常,我只是使用它的初始化器,但它永远不会被调用。我认为这是因为initWithCoder:
总是使用它,它是为故事板指定的。
问题:
- 可以将视图控制器初始化程序与情节提要一起使用吗?看起来不像,类似于appDelegate。
- 这是直接从程序集中使用情节提要的最简单方法吗?
- 如果我有几个故事板,有没有办法以参数方式定义故事板?我不想以
storyBoard1, storyBoard2, ..., storyBoardN
.
提前致谢。