0

我的應用程序發送到UIViewController中的結構類似於如下:如何將事件從另一個

1. UITabbarController 
     1.1 UIViewController 
     1.2 UINavigationController   
      1.2.1 UIViewController 
      1.2.2 UIViewController 
      1.2.3 UIViewController 

它們顯示在以下順序:用戶與1.2完成了它的任務

1, present -> 1.2, 1.2.1, 1.2.2, 1.2.3 

後。 3,1.2 NavigationController被解僱。

我想1.1的UIViewController知道1.2.3已經完成它的工作

我怎麼能做到這一點?

回答

3

有一種簡單的方法來執行(但不是性能方式),您可以使用NSNotificationcenter。 1.1的UIViewController等待通知:

[[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(receiveTestNotification:) 
     name:@"TestNotification" 
     object:nil]; 

當1.2.3完成了它的任務,發佈一個通知:

[[NSNotificationCenter defaultCenter] 
     postNotificationName:@"TestNotification" 
     object:nil]; 
1

您可以使用通知來實現這一目標。

通知

通知檢查@假人的答案。使用通知的好處是,它減少了對象之間不必要的耦合。

另一個髒特技

作爲VC 1.1是UITabbarController部分,就可以訪問它使用

NSArray *viewControllers = [tabBarController viewControllers]; 

現在可以從viewControllers陣列訪問VC 1.1(可能是必須添加iskindofclass驗證),併發送消息給它。 同樣,這是一個骯髒的伎倆。它僅供參考:)

相關問題