Rhubarb によって提案されたRBStoryboardLinkアプローチを調べました。この実装は、奇妙に見えるビュー コントローラーのプロパティを置き換えます。これを回避する方法を見つけたと思います。これがデモプロジェクトです。
ナビゲーション コントローラー
ナビゲーション コントローラは、参照されたビュー コントローラをルートとして設定するだけです。このようなView Controllerの実装は次のようになります。
@interface ExternNavigationController : UINavigationController
@property (strong, nonatomic) NSString *storyboardName;
@property (strong, nonatomic) NSString *sceneIdentifier;
@end
@implementation ExternNavigationController
- (void)awakeFromNib
{
NSAssert(self.storyboardName, @"storyboardName is required");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:self.storyboardName bundle:nil];
UIViewController *vc = self.sceneIdentifier
? [storyboard instantiateViewControllerWithIdentifier:self.sceneIdentifier]
: [storyboard instantiateInitialViewController];
self.viewControllers = @[vc];
}
@end
コントローラを表示
問題は、外部ストーリーボードで定義されたビュー コントローラーをプッシュするときに始まります。これは、プロパティがコピーされる場合です。これの代わりに、偽の宛先コントローラーを外部ストーリーボードからの実際のコントローラーに置き換えるカスタム セグエを実装できます。
@interface ExternStoryboardSegue : UIStoryboardSegue
@end
@implementation ExternStoryboardSegue
- (id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(ExternViewController *)destination
{
NSAssert(destination.storyboardName, @"storyboardName is required");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:destination.storyboardName bundle:nil];
UIViewController *vc = destination.sceneIdentifier
? [storyboard instantiateViewControllerWithIdentifier:destination.sceneIdentifier]
: [storyboard instantiateInitialViewController];
return [super initWithIdentifier:identifier source:source destination:vc];
}
- (void)perform
{
[[self.sourceViewController navigationController] pushViewController:self.destinationViewController animated:YES];
}
@end
ExternViewController はプレースホルダーとして使用され、置換に必要なプロパティ (storyboardName および sceneIdentifier) が含まれています。
@interface ExternViewController : UIViewController
@property (strong, nonatomic) NSString *storyboardName;
@property (strong, nonatomic) NSString *sceneIdentifier;
@end
@implementation ExternViewController
@end
これらのプロパティとプレースホルダー ビュー コントローラーのカスタム クラスを設定する必要があります。また、View Controller と ExternStoryboardSegue をリンクします。
