创建一个 UINavigationController For present 2 UIViewController in Objective-C
Create a UINavigationController For present 2 UIViewController in Objective-C
我有 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];
}
您不会看到第一个视图控制器,因为您已经将第二个视图控制器推送到导航控制器上。
尝试在故事板中嵌入导航控制器,如下所示:
首先 select 你的 testView1
在故事板中。
Select 导航控制器
并变化如下
- (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];
}
我有 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];
}
您不会看到第一个视图控制器,因为您已经将第二个视图控制器推送到导航控制器上。
尝试在故事板中嵌入导航控制器,如下所示:
首先 select 你的 testView1
在故事板中。
Select 导航控制器
并变化如下
- (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];
}