ios - 创建一个 UINavigationController 目前 2 UIViewController 在 Objective-C 中

标签 ios objective-c uinavigationcontroller uinavigationbar uinavigationitem

我有 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

enter image description here

和变化如下

- (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/

相关文章:

ios - Swift 按钮隐藏 fatal error : Array index out of range

ios - 为什么 iOS AWS Cognito 登录不产生错误,但不执行其功能?

ios - 快照如何干扰父/子关系?

ios - withUnsafePointers 不可用

ios - 是否有等效于 gethostbyname 和 inet_ntoa 函数的任何 iOS SDK?

ios - 快速更改导航栏颜色时出现覆盖

iphone - 如何设置日期格式MMM dd,yyyy HH :mm in iPhone

objective-c - 检查后立即设置一个 BOOL

iphone - 标签栏隐藏在基于标签栏的应用程序中

iphone - 如何在通过 Storyboard添加的 UINavigationController 中设置 UINavigationItem 的颜色?