当我在台风中使用故事板时,如果我在程序集中做类似的事情
- (id)myController
{
return [TyphoonDefinition withClass:[BigController class] configuration:^(TyphoonDefinition *definition) {
[definition injectProperty:@selector(dao) with:[_dataAssembly dao]];
}];
}后来,我希望工厂把台风故事板上的控制器交给我,但是我最终得到了使用alloc/init创建的普通控制器。
vc= [_factory componentForType:[BigController class]];在AppDelegate中,我使用台风故事板如下所示
TyphoonComponentFactory *factory = [[TyphoonBlockComponentFactory alloc] initWithAssemblies:@[[Q_Assembly assembly],[P_Assembly assembly]]];我可以回到使用StoryboardWithIdentifier...but,我想使用_factory,以便能够从故事板中获得对控制器的引用。
发布于 2014-06-15 06:52:39
您是否尝试过将故事板声明为工厂组件?下面是一个例子:
//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"];
}];您现在应该能够从工厂解析这个组件了。此特性的文档( https://github.com/typhoon-framework/Typhoon/wiki/Types%20of%20Injections#injecting-objects-produced-by-other-components. )
顺便说一句,我注意到您正在使用TyphoonComponentFactory接口解析控制器,这很好。但是,您知道TyphoonComponentFactory可以充当任何一个组装接口吗?因此,您还可以按以下方式进行解析:
UIViewController* viewController = [(MyAssemblyType*) factory firstVc];。。。这对以下方面特别有用:
示例:
@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;
@endhttps://stackoverflow.com/questions/24223721
复制相似问题