将变量传递给父视图?
我有一个 UITableViewController ,它推送一个 UIViewController ,我需要将两个 NSDate 和一个 BOOL 从该子视图控制器传递回表视图控制器。
我怎么能这样做呢?如果我不清楚或者您需要更多解释,请告诉我。
我将不胜感激任何帮助,谢谢。
I have a UITableViewController which pushes a UIViewController and I need to pass two NSDates and a BOOL from that child view controller back to the table view controller.
How could I do this? Let me know if I am not being clear or you need more explanation.
I'd appreciate any help, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用委托是将信息从一个控制器传递到另一个控制器的正确方法。
一般来说,您要做的就是在
UITableViewController
标头中声明一个协议,实现它,然后使用委托初始化UIViewController
。简而言之,您的
UITableViewController .h
文件应该包含如下内容:然后,您应该实现上述类,对
UITableViewController .m< 中的日期执行您想要执行的任何操作/代码> 文件。
在你的 UIViewController 中,你可以(最后选择)定义一个自定义 init 方法:
首先,在 .h 中定义一个委托属性和一个自定义 init 方法,然后在 .m 中使用它来实现它像这样的事情:
接下来,当您需要将日期传递给
UITableViewController
时,只需使用[self.delegate setDateOne:one dateTwo:two];
还有更多方法可以做到这一点,包括跳过自定义 init 方法并在创建
UIViewController
后设置委托:这更多的是个人喜好风格。
我可能搞乱了代码(并且忘记了一些位),因为我是凭空写下这段代码的,但它应该足以让您开始使用。
Using a delegate is the proper way of passing info from one controller to another.
Generally, what you want to do is to declare a protocol in your
UITableViewController
header, implement it, and then init theUIViewController
with a delegate.In a nutshell, your
UITableViewController .h
file should have something like this:Then, you ought to implement the above mentioned class doing whatever you want to do with the dates in your
UITableViewController .m
file.In your
UIViewController
, you could (alternative at the end) define a custom init method:First, define a delegate property in your .h, and a custom init method, then implement it in your .m with something like this:
Next, when you need to pass the dates to your
UITableViewController
, just use[self.delegate setDateOne:one dateTwo:two];
There are more ways of doing this, including skipping the custom init method and just setting the delegate after you create a
UIViewController
:It's more of a personal preference style.
I've probably messed up the code (and forgotten a few bits) because I'm writing this off the top of my head, but it should be good enough to get you started.