我为不同的用例使用不同的故事板。我的问题是如何通过它的故事板标识符实例化故事板,视图控制器并将其连接到实际的viewcontroller类?
我现在就在这里:
public dynamic func loadingViewController() -> AnyObject {
return TyphoonDefinition.withClass(LoadingViewController.self) {
(definition) in
definition.injectProperty("presenter", with: self.loadingPresenter())
}
// return TyphoonDefinition.withFactory(self.storyboard(), selector: "instantiateViewControllerWithIdentifier:") {
// (factory) in
//
// factory.injectParameterWith("LoadingViewController")
//
// }
}
public dynamic func storyboard() -> AnyObject {
return TyphoonDefinition.withClass(TyphoonStoryboard.self) {
(definition) in
definition.useInitializer("storyboardWithName:factory:bundle:") {
(initializer) in
initializer.injectParameterWith("Loading")
initializer.injectParameterWith(self)
initializer.injectParameterWith(NSBundle.mainBundle())
}
definition.scope = TyphoonScope.Singleton
}
}
在此示例中,故事板的名称为“正在加载”,“视图控制器”是“LoadingViewController”'故事板标识符也是“LoadingViewController'。
”任何帮助(或示例代码)都将不胜感激!
答案 0 :(得分:2)
创建表示将从故事板发出的UIViewController的TyphoonDefinition:
为故事板创建定义:
- (UIStoryboard *)storyboard
{
return [TyphoonDefinition withClass:[TyphoonStoryboard class]
configuration:^(TyphoonDefinition *definition) {
[definition useInitializer:@selector(storyboardWithName:factory:bundle:)
parameters:^(TyphoonMethod *initializer) {
[initializer injectParameterWith:@"StoryboardName"];
[initializer injectParameterWith:self];
[initializer injectParameterWith:[NSBundle mainBundle]];
}];
}];
}
如果您要实例化标记为“' initial'故事板中的控制器:
- (UIViewController *)initialControllerFromStoryBoard
{
return [TyphoonDefinition withFactory:[self storyboard]
selector:@selector(instantiateInitialViewController)];
}
如果您想要在故事板中实例化另一个控制器:
- (UIViewController *)arbitraryControllerFromStoryboard
{
return [TyphoonDefinition withFactory:[self storyboard]
selector:@selector(instantiateViewControllerWithIdentifier:)
parameters:^(TyphoonMethod *factoryMethod) {
[factoryMethod injectParameterWith:@"ViewControllerId"];
}];
}
很抱歉在Objective-C中回复,但我现在还没有得到我的Swift印章。