1つのストーリーボードファイルに3つの異なるViewControllerを作成し、それぞれにストーリーボードIDを与えることができます。それらをセグエと接続しないでください。次に、コンテナビューを表示する場所にドロップし、自動生成されたViewControllerを削除します。
次に、私にとって次のコードが機能します。
-(void)loadSubviewAtIndex:(NSUInteger)idx;
{
[self.subviewController.view removeFromSuperview];
[self.subviewController removeFromParentViewController];
NSString* subviewIdentifier = [self.subviewIdentifiers objectAtIndex:idx];
subviewController = [self.storyboard instantiateViewControllerWithIdentifier:subviewIdentifier];
CGRect frame = self.view.bounds;
subviewController.view.frame = frame;
[self.view addSubview:self.subviewController.view];
[self addChildViewController:self.subviewController];
}
ここsubviewIdentifiers
では、NSArrayであるプロパティと、セグメント化されたコントロールインデックスのストーリーボードIDへの暗黙のマップがありIBOutlet UIViewController* subviewController
、コンテナビューをリンクしていると仮定します。セグメント化された制御アクションからこのメソッドを呼び出すだけです。