iOS:与父视图控制器通信 [英] iOS: Communicating to parent view controller

查看:78
本文介绍了iOS:与父视图控制器通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

父视图控制器是一个单词表。子视图在屏幕上显示,并允许您使用该词。用户可以标记该单词(保存到用户默认值)。父表如何找出该单词已被标记,以便我们可以显示漂亮的标志图标?

Parent view controller is a table of words. Child view segues on the screen and lets you play with that word. User can "flag" the word (which saves into user defaults). How should the parent table now find out that word has been flagged so we can display a pretty flag icon?

推荐答案

要将数据从子视图控制器传回给父视图控制器,您需要使用协议和代理

To pass data back from child to parent view controller you need to use Protocols and Delegates

参见传递数据部分view-controllers> this SO接受了答案,详细解释了在视图控制器之间来回传递信息

See Passing Data Back section of this SO accepted answer for detailed explanation about passing information back and forth between view controllers

你可以拥有子视图控制器中的 boolean

您可以将该布尔值设置为true当用户标记它时。

You can set that boolean to true when the user "flags" it.

如上所示,您可以将值发送回父视图控制器,无论它是否已被标记或不是。

As shown above you can send back the value to the parent view controller whether it has been flagged or not.

希望这有帮助。

这篇关于iOS:与父视图控制器通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆