gpt4 book ai didi

ios - UI 导航栏标题和右栏按钮显示在我拥有的所有 View Controller 中

转载 作者:行者123 更新时间:2023-11-29 00:56:27 24 4
gpt4 key购买 nike

我有一个带有 Storyboard和 2 个 View Controller 的应用程序。我已经通过 Appdelegate 以编程方式创建了导航 Controller 。我在 Viewcontroller1 的 viewDidLoad() 中将标题设置为“Screen1”,并添加了一个右栏按钮。

现在,我的问题是,当我单击右侧栏按钮时,会显示 viewcontroller2,标题设置为“Screen1”,并且右侧栏按钮也会出现。

注意:在ViewController2中,我没有设置任何标题,也没有添加任何栏按钮。

我的代码:

AppDelegate.m: -> didFinishLaunchingWithOptions():

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    
VC1 = [[ViewController1 alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController:self.VC1];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];

ViewController1.m -> didViewLoad():

self.navigationItem setTitle:@"first slide"];

UIBarButtonItem *goto2 = [[UIBarButtonItem alloc] initWithTitle:@"Goto to 2" style:UIBarButtonItemStylePlain target:self action:@selector(GotoSlide2)];
[self.navigationItem setRightBarButtonItem:goto2];


-(void) GotoSlide2
{
ViewController2 *vc2 = [[ViewController2 alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];

}

最佳答案

如果想在ViewController2中隐藏导航栏,在ViewController2的viewDidLoad中编写如下代码:

self.navigationController.navigationBarHidden=YES;

它将隐藏 ViewController2 的 navigationBar

编辑:要隐藏标题,请在 ViewController2 的 viewDidLoad 中编写以下代码:

self.navigationItem.titleView = [[UIView alloc] initWithFrame:CGRectZero];

UILabel *label = [[UILabel alloc] init];
self.navigationItem.titleView = label;

来自这个答案:https://stackoverflow.com/a/2461163/5575752

隐藏右栏按钮:

self.navigationItem.rightBarButtonItem.title = @"";
self.navigationItem.rightBarButtonItem.enabled = NO;

关于ios - UI 导航栏标题和右栏按钮显示在我拥有的所有 View Controller 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37584336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com