微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

iOS-对NavigationItem的更改已应用但不可见

如何解决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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?