Swift BarButtonItem doesn't update

95 Views Asked by At

I have a navigation controller and a root view controller. On this vc I present a table view controller as popover. When a row is selected on this tvc, I execute a delegate method (I know that it is executed) and dismiss the tvc. The delegate is my view controller, so it executes the delegate method:

    func languageDidChange() {
    //selectedLanguageShort = a String
    languageItem.title = LanguageTVC.selectedLanguageShort
    initImageOCR(lang: LanguageTVC.selectedLanguageShort)
    print("This method is executed!")
}

The line is printed, but the title of the item (a UIBarButtonItem outlet) doesn't change. I assume this is caused because there is no segue or anything, so the vc doesn't get updated, but I couldn't find a way to update it manually.

1

There are 1 best solutions below

2
Muhammed Karakul On

You can look at this link: How do I set title for UIBarButtonItem?

And shortly you can try this statement:

navigationItem.rightBarButtonItem = UIBarButtonItem(title: LanguageTVC.selectedLanguageShort, style: .done, target: self, action: nil)