@Claude31
I always appreciate to see your replies on this forum :)
For brevity, I hope you don't mind that I share a smaller example instead. Also, sorry for not replying as a comment. I could not fit an example.
protocol StoryboardBased: UIViewController {
// instantiates a view controller from a storyboard
// default impl based on UIStoryBoard(name:bundle:).instantiateViewController(withIdentifier:)
func makeFromStoryboard() -> Self
}
class ViewController: UIViewController, StoryboardBased {
required init?(coder: NSCoder) {
super.init(coder: coder)
_init()
}
override init(nibName nibNameOrNIl: String?, bundleName bundleNameOrNil: String?) {
super.init(nibName: nibNameOrNIl, bundleName: bundleNameOrNil)
_init()
}
private func _init() {
// init is the earliest time you can update the title correct?
// also doesn't work if I set in viewDidLoad(:) for reference
// or if I set directly from outside prior to instance being pushed
navigationItem.title = makeTitleFromDynamicData() // makeTitleFromDynamicData returns a (non-optional) String
}
}
// Parent is in Navigation Stack
class ParentViewController: UIViewController {
@IBAction func buttonTouchUpInside(_ sender: Any?) {
// push a view controller in response to the user pressing a button
navigationController.pushViewController(
ViewController.makeFromStoryboard() // instantiate Storyboard-based ViewController,
animated: true
)
}
}
Thanks,
smkuehnhold
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: