将对象从VC传递到App Delegate [英] Pass object from VC to App Delegate

查看:70
本文介绍了将对象从VC传递到App Delegate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VC中有一些对象,希望可以从我的应用程序委托中访问。

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

我的VC启动另一个应用程序,该应用程序对我的应用程序进行回调。此回调会触发我的应用程序委托中的方法:

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

但是我想使用在先前的VC中设置的此方法访问一些对象。有什么想法吗?

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

推荐答案

使用

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

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

在委托人中。在.h中使对象数据类型可变,并设置其属性。
编写这样的方法:

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
}

使用方法:

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

这篇关于将对象从VC传递到App Delegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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