UINavigationController 标题和按钮

发布于 2024-09-30 23:14:39 字数 402 浏览 5 评论 0原文

我有一个 UINavigationController,在其中推送/显示其他几个 UIViewController。我希望特定的标题和按钮(准确地说是取消按钮,出现在右侧)始终出现在 UINavigationControllerUINavigationBar 中,无论视图控制器显示在导航控制器中。目前,我已将每个视图控制器的 .title.navigationItem.rightBarButtonItem 设置为相同,但这似乎(a)浪费了很多精力; (b) 当一个新的视图控制器被推入堆栈时,会出现一个简短的动画,其中可以看到标题和按钮以动画方式退出然后再返回 - 显然是不可取的,因为我想让这些项目看起来是静态的并且永远不会改变。

任何建议将不胜感激。

I have a UINavigationController in which I push / display several other UIViewControllers. I would like a specific title and button (a Cancel button to be precise, which appears on the right-hand side) to always appear in the UINavigationController's UINavigationBar regardless of the view controller being displayed within the navigation controller. At the moment I have set the .title and .navigationItem.rightBarButtonItem of each individual view controller to be the same, but this seems like (a) a lot of wasted effort; and (b) when a new view controller is pushed onto the stack there is a brief animation where the title and button can be seen animating out and then back in - obviously not desirable since I want to give the appearance that those items are static and never change.

Any suggestions would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

同展鸳鸯锦 2024-10-07 23:14:39

尝试在 UINavigationController 中设置您需要的所有内容,然后在 UIViewControllers 子类的 viewWillAppear 中粘贴:

[self.navigationItem setLeftBarButtonItem:self.navigationController.navigationItem.leftBarButtonItem];
[self.navigationItem setRightBarButtonItem:self.navigationController.navigationItem.rightBarButtonItem];

Try to set all you need in UINavigationController and then in viewWillAppear of your UIViewControllers subclasses paste:

[self.navigationItem setLeftBarButtonItem:self.navigationController.navigationItem.leftBarButtonItem];
[self.navigationItem setRightBarButtonItem:self.navigationController.navigationItem.rightBarButtonItem];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文