0

I want to thank in advance for your help. My issue is that I'm trying to set the title as a attributed String. I'm using the Storyboard and I have embedded the rootViewController in a NavigationController. The code I have for now is:

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")
    }
}

Unfortunately, this code has an output that would suggest that this worked:

Navigation Controller: <UILabel: 0x7fe43a407b40; frame = (0 0; 0 0); text = 'Beaucarnea recurvata Lem.'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x600000274140>>

As we can see by the "text = 'Beaucarnea recurvara Lem'". However it doesn't show that as the title. Note that I also tried to set the title of the back button to empty and it also didn't change as we can see in the following screenshot:

enter image description here

This has been a recurring issue I've tried to change things in the navigation bar, they seem to have been applied but in reality they are not displayed anywhere. I tried changing the position of the code from viewDidLoad to viewWillAppear but nothing. I tried debugging the view hierarchy and everything from What I gather the titleLabel is just gone.

enter image description here

So I really don't know what to do. If you need anymore code or need anything else I am glad to help.

0 Answers0