我有2个UIViewController
,并且要在其上具有UINavigationBar和UINavigationItem的UINavigationController。但是我的代码不起作用..
这是我的代码:
#import "testView1.h"
#import "testView2.h"
@interface testView1 ()
@end
@implementation testView1
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor darkGrayColor];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self];
testView2 *detail = [testView2 new];
[navController pushViewController:detail animated:YES];
}
最佳答案
尝试将导航控制器嵌入情节提要中,如下所示:
首先在情节提要中选择testView1
。
选择导航控制器
和变化如下
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
/// testView2 *detail = [testView2 new];
testView2 *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"testView2 Identifier"]; // if you have add controller in storyboard
[self.navigationController pushViewController:detail animated:YES];
}
关于ios - 在Objective-C中为当前的2个UIViewController创建一个UINavigationController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45142716/