Apple introduces storyboard reference from iOS 9, which provides a placeholder for scene in external storyboard. But due to the version limitation, it's not that practical. What's more, it's not friendly to unit test, which rises the risk of refactoring. ZZStoryboardReference is a alternative of that.
You just need dragging a view controller(called A) scene to the storyboarad, set its class to ZZStoryboardReference, replace the content view with a label, then set the label's text to another view controller's (called B) name which can instantiate from storyboard. (I recommend copying the sence in the demo and modify the label's text) Now A is a place holder of B, We can link segue to A when it's not convenient for B. In addition, B should override the storyboardName method as the demo shows.
If you want to instantiate view controller from stroyboard with code:
ZZRedViewController *redVC = [ZZRedViewController newFromStoryboard];
[self.navigationController pushViewController:redVC animated:YES];
What's more, this mechanism makes unit test for storyboard scene easy. I write a unit test in the demo, when we move a scene for a storyboard to another and forget modifing the storyboardName method, the unit test would rise a exception.
To run the example project, clone the repo, and run pod install
from the Example directory first.
ZZStoryboardReference is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ZZStoryboardReference'
ddhjy, 510893492@qq.com
ZZStoryboardReference is available under the MIT license. See the LICENSE file for more info.