使用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
本文详细介绍了如何利用宏和在AppDelegate类中添加静态方法来创建全局变量,适用于iOS开发中需要跨多个视图控制器共享数据的场景。

1万+

被折叠的 条评论
为什么被折叠?



