在台风中使用故事板时,如果我在程序集中执行类似的操作
- (id)myController
{
return [TyphoonDefinition withClass:[BigController class] configuration:^(TyphoonDefinition *definition) {
[definition injectProperty:@selector(dao) with:[_dataAssembly dao]];
}];
}
后来我希望工厂将 Typhoon 故事板中的控制器交给我,但最终我得到了使用 alloc/init 创建的普通控制器
vc= [_factory componentForType:[BigController class]];
在 AppDelegate 中,我使用台风故事板,如下所示
TyphoonComponentFactory *factory = [[TyphoonBlockComponentFactory alloc] initWithAssemblies:@[[Q_Assembly assembly],[P_Assembly assembly]]];
我可以回去使用 Storyboard WithIdentifier...但我想使用_factory
能够从情节提要中获取我想要的控制器的引用。
您是否尝试过将故事板声明为工厂组件?这是一个例子:
//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"];
}];
您现在应该能够从工厂解析此组件。此功能的文档is here.
顺便说一句,我注意到您正在使用 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)