Pass object from VC to App Delegate

为君一笑 提交于 2019-12-24 22:15:11

问题


I have a few objects in a VC that I want to be accessible from my App Delegate.

My VC launches another app, which does a callback to my app. This callback triggers a method in my App Delegate:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

But I want to access some objects in this method that I had set in that previous VC. Any ideas how?


回答1:


Use

+(id)sharedApplicationDelegate; in delegate.h, and write

+(id)sharedApplicationDelegate{
    return  [[UIApplication sharedApplication] delegate];
}

In delegate.m. Make object data type variable in .h and set its property. Write a method like this:

-(void)setObjectForDelegate:(ObjectType *)value{
//use value obj or set it to other variable
}

How to Use:

#import “XXXXdelegate.h”
[[UIApplication sharedApplication] setObjectForDelegate:object];


来源:https://stackoverflow.com/questions/8162777/pass-object-from-vc-to-app-delegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!