gpt4 book ai didi

ios - 标题有什么不同?

转载 作者:搜寻专家 更新时间:2023-11-01 06:17:30 25 4
gpt4 key购买 nike

我想为我的 UIViewController 添加标题:

我试过了

self.navigationController.navigationItem.title
self.navigationController.title
self.title

有时,解决方案 1 有效,有时解决方案 2 有效,有时解决方案 3 有效。

哪位高手能告诉我它们之间的区别吗?

最佳答案

titleUIViewController 的属性。

A localized string that represents the view this controller manages. Set the title to a human-readable string that describes the view. If the view controller has a valid navigation item or tab-bar item, assigning a value to this property updates the title text in those objects.


self.navigationController 是一个 UINavigationController,它管理 viewController 所在的 viewController 堆栈。UINavigationControllerUIViewController 的子类,所以 self.navigationController.titleUINavigationControllertitle


self.navigationItem.title:

The navigation item’s title displayed in the center of the navigation bar. The default value is nil. When the receiver is on the navigation item stack and is second from the top—in other words, its view controller manages the views that the user would navigate back to—the value in this property is used for the back button on the top-most navigation bar. If the value of this property is nil, the system uses the string “Back” as the text of the back button.


因此,在实践中,您应该设置 ViewControllertitle。如果您的 ViewControllerUINavigationController 管理,iOS 会将此标题复制到导航项或标签栏项并在导航栏上显示此标题,当您按下另一个 ViewController 时,它会将该文本用于 Back Button,并且如果您的 ViewController 将它显示在选项卡栏中由 UITabBarController 管理。

关于ios - 标题有什么不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41208404/

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