如何从视图控制器类访问AppDelegate类中声明的对象?

时间:2016-08-04 13:58:01

标签: ios objective-c appdelegate

这是我的{% extends 'base.html' %} {% load sekizai_tags %} {% block 'content' %} <p>that's some sweet content ya got there lad</p> {% addtoblock "extra" %}wow{% endaddtoblock %} {% endblock %}

AppDelegate.h

这是我的@interface AppDelegate : UIResponder <UIApplicationDelegate> { ProductHandlerModel *handler; } @property (strong, nonatomic) UIWindow *window; -(ProductHandlerModel*)getHandler; @end

AppDelegate.m

如何从另一个- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { handler = [[ProductHandlerModel alloc]init]; return YES; } - (ProductHandlerModel*)getHandler { return handler; } 类访问此处理程序对象?

1 个答案:

答案 0 :(得分:3)

一样打电话
AppDelegate *delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
[delegate getHandler];

或简单地称为

[(AppDelegate *)[[UIApplication sharedApplication] delegate] getHandler];

别忘了导入。

#import "AppDelegate.h"