There are 2 viewControllers in a navigationController: navigationController->root->A In viewController A, if a user make some settings and press the left bar button item(Back), I want the root view to renew its layout(some views' size will be changed).
By now, I make it works by adding one more navigationController between the two viewControllers(present modally): navigationController->root->navigationController->A.
Is there a way to renew the root viewController with one navigationController?(Screenshot 1)
Thanks.
----- Edited -----
Sample codes:
override func viewWillAppear(_ animated: Bool) {
creatButtons()
}
func createButtons(){
let button1 = UIButton()
........
let button2 = UIButton()
........
.......
}
If I create 16 buttons under viewWillAppear(), will all the buttons be duplicated when comes back from A? Their size are all need to be renewed.
RootViewController
SecondVC - You can read as A view Controller
Not sure if I understood your question correctly but here are two alternatives on how to handle this scenario:
If you want to refresh the view hierarchy of
root
when settings are changed inA
just make sure to persist the changes in a place that bothroot
andA
can access. Override the-viewWillAppear:
(will be triggered on "back" as well) method inroot
and layout the view according to the settings every time.Other alternative:
You could create a
delegate protocol
forA
that is implemented byroot
and assignroot
asA
'sdelegate
whenroot
instantiates or presentsA
.A
would then invoke its delegate (root
) to inform it about the change and letroot
update its views.