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验证),并发送消息给它。 同样,这是一个肮脏的伎俩。它仅供参考:)

相关问题