我正在为 iPhone 开发一个应用程序,我需要在其中发送消息topViewController
到rootViewController
.
一种解决方案可能是在导航堆栈中的每个 VC 中创建委托方法并相应地调用,以便消息到达rootViewController
. 但在这种情况下,消息必须通过整个导航堆栈。
任何机构都可以用最好的方法帮助我吗
谢谢
一种选择是访问rootViewcontroller
,
RootViewController *rootViewController = (RootViewController *)[self.navigationController.viewControllers objectAtIndex:0];
然后对这个对象做必要的操作。navigationController.viewControllers
返回导航堆栈中的所有视图控制器。
在任何 topViewController 方法中,您都可以通过以下方式提取导航堆栈的 rootViewController
[self.navigationController.viewControllers objectAtIndex:0];