全局变量

ios开发中,全局变量设置和调用方法如下:
在AppDelegate.h文件中设置全局变量:
@interface ***AppDelegate{
NSString *myName;
}
@property (nonatomic, retain) NSString  *myName;
@end
在AppDelegate.m文件中实现全局变量:
@synthesize myName;
假如在 CallBack页面调用,在CallBack.m中包含AppDelegate.h文件,并定义一个代理实例,如下
#import "AppDelegate.h"
在 - (void)****{
   AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
  myDelegte.myName = @"123 ";
}

猜你喜欢

转载自duchengjiu.iteye.com/blog/1893360