問題描述
在兩個視圖控制器之間傳遞數據的例子有很多,其中一個視圖控制器導航到另一個視圖控制器.
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 鏈接.
這篇關于在沒有任何導航控制器連接的情況下使用視圖控制器之間的委托傳遞數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!