在两个视图控制器之间传递数据的例子有很多,其中一个视图控制器导航到另一个视图控制器.
There are many examples of passing data between two view controllers, where one view controller navigates to another view controller.
但是是否可以使用自定义协议传递数据?未通过导航控制器连接的视图控制器之间的委托?
But is it possible to pass data using custom protocols & delegates between view controllers that are not connected by navigation controller?
所以,一个例子可以是:三个视图控制器,即A
、B
、C
.A
导航到 B
,B
导航到 C
.我知道如何在 A
& 之间传递数据B
使用自定义协议 &代表.但是我们可以在 C
& 之间传递数据吗?A
.因此A
可以是C
的委托,从而可以从C
接收数据.这可能吗?
So, an example could be: Three view controllers namely are, A
,B
,C
. A
navigates to B
, and B
navigates to C
. I know how to pass data between A
& B
using custom protocols & delegates. But can we pass data between C
& A
. Thus A
can be C
's delegate and thereby can receive data from C
. Is this possible?
任何帮助将不胜感激.
一种方法是使用 委托 向后传递数据
One way is use delegates for backward passing of data
参考 simple-delegate-tutorial-for-ios 用于将数据从 C 传递到 A 控制器的链接.
Refer simple-delegate-tutorial-for-ios link for passing data from C to A controller.
检查 basic-delegate-example 链接.
另一种方法是发布通知.用于向后传递数据
Another way is by posting notification. for backward passing of data
检查 Communicate-Two-Views 链接.
这篇关于在没有任何导航控制器连接的情况下使用视图控制器之间的委托传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!