What I want to achieve?
I have 2 UITableViewController : AddCardVC
and ListDeckController
. I want to pass selected Deck in ListDeckController
to AddCardVC
then updateUI
on AddCardVC
My code: (I'm building on Swift 5
, iOS 13
)
ListDeckController.swift:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let addCardVC = storyboard.instantiateViewController(withIdentifier: "AddCard") as? AddCardVC {
if let deck = allDecks?[indexPath.row] {
addCardVC.selectedDeck = deck
}
}
self.navigationController?.popViewController(animated: true)
}
AddCardVC.swift:
var selectedDeck: Deck?
{
didSet {
viewWillAppear(true)
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let deck = selectedDeck {
//Update UI
self.chooseDeckButton.setTitle(deck.name, for: .normal)
print(chooseDeckButton.titleLabel?.text ?? "")
self.tableView.reloadData()
}
}
What happend?
After I got selected Deck in AddCardVC
, the console print out chooseDeckButton.titleLabel?.text = "My Deck"
which is what I want. But The button title on UI is "Choose your deck"
Console image Button on UI
So, why the setButtonTitle not showing on UI in my case?
Thank you for your time