您是否尝试过将故事板声明为工厂组件?这是一个例子:
//Create the factory definition
-(id)myStoryBoard
{
return [TyphoonDefinition withClass:[TyphoonStoryboard class] configuration:
^(TyphoonDefinition* definition) {
[definition useInitializer:@selector(storyboardWithName:factory:bundle) parameters:
^(TyphoonInitializer* initializer) {
[initializer injectParameterWith:@"storyBoardName"];
[initializer injectParameterWith:self];
[initializer injectParameterWith:[NSBundle mainBundle]];
}
definition.scope = TyphoonScopeSingleton; //Let's make this a singleton
}
}
//Create definitions that will be emitted by the factory
-(id)firstVc
{
return [TyphoonDefinition withFactory:[self myStoryBoard]
selector:@selector(instantiateViewControllerWithIdentifier:)
parameters:^(TyphoonMethod *factoryMethod) {
[factoryMethod injectParameterWith:@"viewControllerId"];
}];
您现在应该能够从工厂解决此组件。此功能的文档在此处。
顺便说一句,我注意到您正在使用 TyphoonComponentFactory 接口解析控制器,这很好。但是您知道 TyphoonComponentFactory 可以作为您的任何装配接口吗?所以也可以这样解决:
UIViewController* viewController = [(MyAssemblyType*) factory firstVc];
. . . 这对于以下情况特别有用:
- 这样您就可以注册多个相同类型的组件,并在没有“魔术字符串”的情况下对其进行解析。
- 当您注入工厂本身时,要在 Typhoon 上进行更松散的耦合。
例子:
@interface MyListViewController
//In the assembly we inject 'self'.
//We'll obtain the detail VC using the "domain specific" assembly interface.
//. . but when injecting self, it can be cast to TyphoonComponentFactory or any of your
//assembly interfaces
@property(nonatomic, strong, readonly) MyAssembly* assembly;
@end