I need something like this self.parentViewController.someValue = 20
. Is it possible? I use UINavigationBar. And I want when user tapped on back button, some value in my main controller changed.
I can think of four ways to do this and there are probably more that aren't coming to mind.
1) Update a data model and have the parent controller be an observer of the change using KVO.
2) Send a notification when the second controller is going away and have the parent listen for it.
3) Create a delegate protocol that lets the second controller reference a parent method directly.
4) Use the parent's viewWillAppear:
and check the isMovingToParentViewController
property for whether it's just re-appearing.
You have lots of choices! :)
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.