我想以两种模式显示一些数据,因此通过单击 UINavigationControlle 中名为“switch”的 UIBarButtonItem。
我可以使用 Storyboard 和 xib 来做到这一点,但我只想知道如何只使用 Storyboard 来实现它。
使用情节提要和 xib:
#import "ViewController.h"
#import "ViewControllerOne.h"
#import "ViewControllerTwo.h"
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
ViewControllerOne *view1 = [[ViewControllerOne alloc] init];
ViewControllerTwo *view2 = [[ViewControllerTwo alloc] init];
[self.view insertSubview:view1.view atIndex:1];
[self.view insertSubview:view2.view atIndex:0];
}
- (IBAction)switchButton:(id)sender
{
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
}
如果我只使用 Storyboard 和上面的代码,那么什么都没有发生,视图就是空的: