UINavigationControllers:如何将值传递给堆栈中的更高(父?)控制器?
我有 SendingController,它推送到导航堆栈 SendingDeatilsController (其中一个有 TableView)。用户应该在 TableView 中选择一行(通过复选标记检查),我想将这一行的值(让它成为 NSString 对象)传递给 SendingController。
我如何在我的应用程序中实现这种行为?并且SendingController是SendingDetailController的父级(SDC的属性parentController指的是SC)?
I have SendingController which push to nav stack SendingDeatilsController (which one has a TableView). User should should pick in TableView one row (it checked by Checkmark) and I would like to pass the value of this row (let it will NSString object) to the SendingController.
How can I realize this behaviour in my application? And is SendingController parent for SendingDetailController (attribute parentController of SDC refers to SC) ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想实现此行为,请将对前一个视图控制器的引用传递给
SendingDetailController
。这样,详细视图控制器可以向堆栈上的前一个视图控制器发送消息。在您的
SendingDetailController
中定义一个弱引用:现在,在将
SendingDetailController
推入堆栈之前,不要忘记设置其sendingController
属性。并编写将接收字符串的方法。
这应该可以完成工作。
If you want to implement this behaviour, pass the
SendingDetailController
a reference to the previous view controller. This way the detail view controller can send a message to the previous one on the stack.In your
SendingDetailController
define a weak reference :Now before pushing the
SendingDetailController
on the stack don't forget to set itssendingController
property.and write the method that will recieve the string.
This should do the job.
为了在不同的 UIViewController 之间轻松进行异步通信,您可能需要查看 NSNotification 和 NSNotificationCenter。
网上有很多教程,SO 上有一些很好的答案,可以向您展示如何准确地做到这一点。
For easy asynchronous communication between different UIViewControllers, you may want to look at NSNotification and NSNotificationCenter.
There are plenty tutorials on the web and some good answers here at SO that can show you how to do that exactly.