简体   繁体   中英

Swift BarButtonItem doesn't update

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM