我有 2 个 UIViewController,并且希望 UINavigationController 上带有 UINavigationBar 和 UINavigationItem。但我的代码不起作用..
这是我的代码:
#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];
}
最佳答案
尝试在 Storyboard中嵌入导航 Controller ,如下所示:
首先在 Storyboard中选择您的testView1
。
选择导航 Controller
和变化如下
- (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 - 创建一个 UINavigationController 目前 2 UIViewController 在 Objective-C 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45142716/