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'”看到。但是,它没有将其显示标题。请注意,我还尝试将后退按钮的标题设置为空,并且也没有变化,如下面的屏幕截图所示:

enter image description here

这是一个反复出现的问题,我尝试在导航栏中进行更改,似乎已经应用了它们,但实际上它们没有显示在任何地方。 我尝试将代码的位置从viewDidLoad更改为viewWillAppear,但是什么也没有。我尝试调试视图层次结构,并且从我收集的titleLabel中获得的一切都消失了。

enter image description here

所以我真的不知道该怎么办。如果您需要其他代码或其他任何内容,我们很乐意为您提供帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)