从detailViewController获取bool值的最佳方法是什么?
在我的基于导航的应用程序中,有一个按钮,如果按下该按钮,会将视图更改为detailViewController。在这里用户可以设置几个选项。这些选项之一是布尔值。当我从detailViewController返回时,我怎样才能看到这个bool值是什么?
In my navigation based app, there is a button that if pressed, will change the view to a detailViewController. Here the user can set several options. One of those options is a bool value. When I return from the detailViewController how can I see what this bool value is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建 协议(
DetailViewDelegate
?)并创建一个delegateDetailViewController
中的属性。当您实例化视图控制器时,将委托属性设置为 self 并使用该属性将消息发送回主视图控制器。唯一棘手的部分是您需要将委托属性声明为“分配”,这样您就不会在详细视图和主视图之间创建保留循环。DetailViewController.h:
这只是界面,但它应该可以帮助您完成大部分工作。设置详细视图的
delegate
属性,并在主视图中实现detailViewController:didChangeBool:
方法,仅此而已。回答您评论中的问题:
delegate
属性设置为self
。detailViewController:didChangeBool:
方法添加到主视图控制器中。Create a protocol (
DetailViewDelegate
?) and create a delegate property in yourDetailViewController
. When you instantiate your view controller, set the delegate property toself
and use that property to send messages back to your master view controller. The only tricky part is that you need to declare the delegate property as "assign" so that you don't create a retain loop between your detail view and master view.DetailViewController.h:
That's just the interface, but it should get you most of the way there. Set the
delegate
property of the detail view and implement adetailViewController:didChangeBool:
method in your master view and that's about it.To answer the questions in your comment:
delegate
property toself
.detailViewController:didChangeBool:
method to your master view controller.