如何解决iOS-对NavigationItem的更改已应用但不可见
在此先感谢您的帮助。我的问题是我试图将标题设置为属性字符串。我正在使用Storyboard,并且已经将rootViewController嵌入了NavigationController中。我现在拥有的代码是:
import UIKit
class PointOfInterestViewControllerTableViewController: UITableViewController {
var selectedPointOfInterest: TourPointOfInterest?
override func viewDidLoad() {
super.viewDidLoad()
do {
let attrStr = try NSMutableAttributedString(
data: (selectedPointOfInterest?.pointOfInterest?.name!.data(using: String.Encoding.unicode,allowLossyConversion: true)!)!,options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html],documentAttributes: nil)
navigationController?.navigationBar.backItem?.title = ""
self.navigationItem.titleLabel.attributedText = attrStr
print("Navigation Controller: \(navigationItem.titleLabel)")
} catch {
print("error loading title")
}
}
Navigation Controller: <UILabel: 0x7fe43a407b40; frame = (0 0; 0 0); text = 'Beaucarnea recurvata Lem.'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x600000274140>>
我们可以通过“ text ='Beaucarnea recurvara Lem'”看到。但是,它没有将其显示为标题。请注意,我还尝试将后退按钮的标题设置为空,并且也没有变化,如下面的屏幕截图所示:
这是一个反复出现的问题,我尝试在导航栏中进行更改,似乎已经应用了它们,但实际上它们没有显示在任何地方。 我尝试将代码的位置从viewDidLoad更改为viewWillAppear,但是什么也没有。我尝试调试视图层次结构,并且从我收集的titleLabel中获得的一切都消失了。
所以我真的不知道该怎么办。如果您需要其他代码或其他任何内容,我们很乐意为您提供帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。