Typhoon: Assembly and Storyboard-Created ViewControllers

回眸只為那壹抹淺笑 提交于 2020-01-11 04:48:05

问题


How would I use Typhoon with iOS storyboards where view controllers are generated implicitly by the system? Would I have to do something special in the prepareForSegue methods?


回答1:


It is very simple with TyphoonStoryboard

By bootstrapping Typhoon in your plist, along with the usual UILaunchStoryboardName and UIMainStoryboardFile, Typhoon will ensure that all Storyboards are an instance of TyphoonStoryboard. Use exactly as you would a normal Storyboard, with the added benefit that dependencies will be injected according to the definitions in your TyphoonAssembly class(es).

Optionally, you can specify which definition should be used for each viewController. For that, use 'typhoonKey' runtime attribute in storyboard. Otherwise the definition matching the controller class will be used. Example:

The documentation for this feature is here.




回答2:


There is a TyphoonStoryBoard component in the backlog, however it hasn't been implemented yet (see update below).

There is currently a -injectProperties: method on the component factory that you can use to apply dependency injection on a component after it has been instantiated, ex. by the story board.

For now, you could subclass UIStoryboard and call the -injectProperties: on the view controller by overriding:

– instantiateInitialViewController
– instantiateViewControllerWithIdentifier:

Example:

- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier {
  id instantiatedViewController = [super instantiateViewControllerWithIdentifier:identifier];
  [[TyphoonComponentFactory defaultFactory] injectProperties:instantiatedViewController];
  return instantiatedViewController;
}

Update:

TyphoonStoryBoard integration has now been completed (pending documentation), and committed to master. It will be released as part of Typhoon 2.0, in the coming weeks.



来源:https://stackoverflow.com/questions/18998759/typhoon-assembly-and-storyboard-created-viewcontrollers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!