問(wèn)題描述
在兩個(gè)視圖控制器之間傳遞數(shù)據(jù)的例子有很多,其中一個(gè)視圖控制器導(dǎo)航到另一個(gè)視圖控制器.
There are many examples of passing data between two view controllers, where one view controller navigates to another view controller.
但是是否可以使用自定義協(xié)議傳遞數(shù)據(jù)?未通過(guò)導(dǎo)航控制器連接的視圖控制器之間的委托?
But is it possible to pass data using custom protocols & delegates between view controllers that are not connected by navigation controller?
所以,一個(gè)例子可以是:三個(gè)視圖控制器,即A
、B
、C
.A
導(dǎo)航到 B
,B
導(dǎo)航到 C
.我知道如何在 A
& 之間傳遞數(shù)據(jù)B
使用自定義協(xié)議 &代表.但是我們可以在 C
& 之間傳遞數(shù)據(jù)嗎?A
.因此A
可以是C
的委托,從而可以從C
接收數(shù)據(jù).這可能嗎?
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?
任何幫助將不勝感激.
推薦答案
一種方法是使用 委托 向后傳遞數(shù)據(jù)
One way is use delegates for backward passing of data
參考 simple-delegate-tutorial-for-ios 用于將數(shù)據(jù)從 C 傳遞到 A 控制器的鏈接.
Refer simple-delegate-tutorial-for-ios link for passing data from C to A controller.
檢查 basic-delegate-example 鏈接.
另一種方法是發(fā)布通知.用于向后傳遞數(shù)據(jù)
Another way is by posting notification. for backward passing of data
檢查 Communicate-Two-Views 鏈接.
這篇關(guān)于在沒(méi)有任何導(dǎo)航控制器連接的情況下使用視圖控制器之間的委托傳遞數(shù)據(jù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!