获取程序Appdelegate中无需释放的特定控制器,非新建-------IOS

来源:互联网 发布:淘宝客api是什么 编辑:程序博客网 时间:2024/06/15 00:13

-----------------------------转载请注明出处------------------------------------

appdelegate的.h中声明一条属性,@property (nonatomic,strong)CenterDrawerViewController *centerViewController1;

.m中新建 self.centerViewController1 = [[CenterDrawerViewController alloc] init];


以下是在其他的控制器中需要获得Appdelegate中的centerViewController1

UIApplication* application = [UIApplication sharedApplication];            AppDelegate* appdelegate = application.delegate;            CenterDrawerViewController * centerViewController = appdelegate.centerViewController1;



这样做的好处就是在我们的项目中,需要用到的抽屉效果或者其他页面切换效果的时候,从这个页面切换到另一个页面,最后切换到原来的页面的时候.原来的页面不会新建,这就节省了用户的部分流量.避免了新建.用户只有通过下拉刷新才会触发刷新功能.

虽然是一个解决办法,但是还是推荐大家使用数据持久化(NSData和归档)来完成这个功能,这个只是权宜之计,只是觉得好玩,就实现一下吧.

0 0