iOS SWRevealViewController-在控制器之间传递数据 [英] iOS SWRevealViewController - pass data between controllers

查看:108
本文介绍了iOS SWRevealViewController-在控制器之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SWRevealViewController在我的应用程序中实现幻灯片菜单(从左侧开始).一切正常,但现在我遇到了一个小问题.我想从我的主"视图控制器(完全可见的那个)传递数据,而我不称它为"frontViewController",因为看起来好像不是前一).我已经尝试过所有可能想到的访问幻灯片菜单控制器并将数据传递给它的可能性.这是我尝试过的:

I am using SWRevealViewController to implement a slide menu (from the left side) in my application. Everything is working fine but now I am facing a little problem.I want to pass data from my "main" view controller (the one that is full visible, and I am not calling it "frontViewController" because it seems like it is not the front one). I have tried all possiblities I can think of to access the slide menu controller and pass data to it. Here is what i have tried:

(MyControllerClass*)self.revealViewController.rearViewController
(MyControllerClass*)self.revealViewController.frontViewController

我尝试过类似self.revealViewController.navigationController[0]self.revealViewController.navigationController[1]以及this,self.revealViewController.viewControllers[0]self.revealViewController.viewControllers[1]之类的东西.下一步是实现prepareforsegue并侦听segue标识符sw_frontsw_rear.但是在所有这些情况下,当我检查isKindOfClass[MyControllerclass class]时都是正确的.我认为这是因为所有这些都是SWRevealViewController类型,不是吗?而且,prepareForSegue根本没有被调用,但是一切都正常显示

Than I tried things like self.revealViewController.navigationController[0], self.revealViewController.navigationController[1], also this , self.revealViewController.viewControllers[0],self.revealViewController.viewControllers[1]. The next step was to implement prepareforsegue and listen for segue identifier sw_front and sw_rear. But in non of these cases, I got true when checking isKindOfClass[MyControllerclass class]. I assume this is because all of these are of type SWRevealViewController, aren't they ? And, prepareForSegue isnt't being called at all, but everything is showing properly

对我来说,主要问题是,如何在侧边菜单和主"(又名前端")控制器之间传递数据(另一种方法也可以)?

The main question for me is, how can I pass data between my side menu and my "main" (aka front) controller (the other way would also be fine)?

谢谢

推荐答案

我得到了答案.您无法通过SWRevealViewController直接访问自己的控制器(因为它已连接到NavigationController).首先,获得所需的navigationController,并通过它们访问控制器(并传递数据).这是理论的代码:

I got the answer. You cannot directly access your own controllers through SWRevealViewController (since it is connected to NavigationController). First you get the navigationController you want and through them you access your controllers (and pass data). Here is the code to the theory:

UINavigationController* rearNavigationController = (UINavigationController*)self.revealViewController.rearViewController; 
//here you get the navigationController which is connected to the controller you want, in my case i want the rear controller

if ([rearNavigationController.topViewController isKindOfClass[MyCustomViewController]]) {
    MyCustomViewController* iWantYouController = (MyCustomViewController*)rearNavigationController.topViewController;
}

就这样.现在,您可以访问(并设置)自定义控制器上的每个属性

And thats it. Now you can access (and set) every property on your custom controller

这篇关于iOS SWRevealViewController-在控制器之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆