[英]Change value in parentViewController when back button in childViewController was pressed
I need something like this self.parentViewController.someValue = 20
. 我需要类似
self.parentViewController.someValue = 20
东西。 Is it possible? 可能吗? I use UINavigationBar.
我使用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. 1)使用KVO更新数据模型,并使父控制器成为更改的观察者。
2) Send a notification when the second controller is going away and have the parent listen for it. 2)当第二个控制器离开时发送通知,让父母听。
3) Create a delegate protocol that lets the second controller reference a parent method directly. 3)创建一个委托协议,该协议使第二个控制器直接引用父方法。
4) Use the parent's viewWillAppear:
and check the isMovingToParentViewController
property for whether it's just re-appearing. 4)使用父级的
viewWillAppear:
并检查isMovingToParentViewController
属性是否只是重新出现。
You have lots of choices! 您有很多选择! :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.