Iphone 在iOS中将消息从topViewController发送到rootViewController

Iphone 在iOS中将消息从topViewController发送到rootViewController,iphone,ios,Iphone,Ios,我正在为iPhone开发一个应用程序,其中我需要将一条消息从topViewController发送到rootViewController 一种解决方案可能是在导航堆栈中的每个VC中创建委托方法并相应地调用,以便消息到达rootViewController。但在这个场景中,消息必须通过整个导航堆栈 有人能用最好的方法帮我吗 谢谢一个选项是访问rootViewcontrolleras RootViewController *rootViewController = (RootViewControll

我正在为iPhone开发一个应用程序,其中我需要将一条消息从
topViewController
发送到
rootViewController

一种解决方案可能是在导航堆栈中的每个VC中创建委托方法并相应地调用,以便消息到达
rootViewController
。但在这个场景中,消息必须通过整个导航堆栈

有人能用最好的方法帮我吗


谢谢

一个选项是访问
rootViewcontroller
as

RootViewController *rootViewController = (RootViewController *)[self.navigationController.viewControllers objectAtIndex:0];

然后在此对象上执行必要的操作
navigationController.ViewController
返回导航堆栈中的所有ViewController。

在任何topViewController方法中,您都可以提取导航堆栈的rootViewController 借


这和下面发布的答案不一样吗?@ACB:是的..也许..我发布这篇文章时晚了几分之一秒:B谢谢,我使用了相同的方法,但有人说它会导致循环依赖,并可能导致内存泄漏等advise@AbdusSamad,这不会导致任何循环依赖<代码>navigationController.ViewController是navigationController可用的属性,可以在任何地方使用。在这种情况下,您只需访问第一个对象并对其执行某些操作。确保你没有把它留在课堂上。
 [self.navigationController.viewControllers objectAtIndex:0];