使用appdelegate的变量做全局变量的方法

来源:互联网 发布:json数组解析 编辑:程序博客网 时间:2024/05/14 20:01

使用appdelegate的变量做全局变量的方法:

1.用宏:

#define kAppDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])


2.在appdelegate上加一个类方法,返回appdelegate:

static AppDelegate *appDeleagate=nil;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


         appDeleagate=self;

}


+(AppDelegate *)delegate{

   return  appDeleagate;

}


原帖:http://my.oschina.net/openlab/blog/151950

0 0
原创粉丝点击