hachinoBlog

hachinobuのエンジニアライフ

Main.storyboardとは別のstoryboardから特定のViewControllerのインスタンスを生成する方法

今更ながらStoryboardの読み込み方法。
前提としてStoryboardの読み込みたいViewConrollerにて[Show the Identity Inspector]の[Storyboard ID]に一意のIDを振っておく。
読み込み方は

//Sub.storyboardの読み込み
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Sub" bundle:nil];
//設定した[Storyboard ID]の値をキーにしてインスタンス生成
SampleViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"sample"];

ちなみにMainの場合は

SampleViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"sample"];