gpt4 book ai didi

objective-c - 添加的按钮未显示在 UINavigationController 上

转载 作者:搜寻专家 更新时间:2023-10-30 19:54:58 29 4
gpt4 key购买 nike

我正在尝试动态创建一个 View Controller 并设置它的 View 和标题栏。事情似乎工作得很好。但是当我尝试设置导航栏的左键或右键时,它们就是不显示。我做错了什么?

   UIWebView *tempWebView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[tempWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"someurl"]]];

UIViewController* tempViewController = [[UIViewController alloc]init];
tempViewController.view = tempWebView;

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tempViewController];

UIBarButtonItem* closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleBordered target:self action:nil];
navigationController.navigationItem.leftBarButtonItem = closeButton;


[self presentViewController:navigationController animated:YES completion:nil];

最佳答案

改变

navigationController.navigationItem.leftBarButtonItem = closeButton;

tempViewController.navigationItem.leftBarButtonItem = closeButton;

navigationItem 外观由导航 Controller 呈现的 View 处理,因此如果您将它设置在 UINavigationController 而不是 rootViewController ,它会在您第一次推送时被覆盖。

关于objective-c - 添加的按钮未显示在 UINavigationController 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15689432/

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