iOS: 设置全局变量
2012-09-18 11:53
363 查看
有几种方法
some developers recommend use singleton patter (ref link http://blog.csdn.net/kmyhy/article/details/7026511)
方法1:使用静态变量 (不推荐)
方法2: 使用singleton pattern (ref link: http://nice.iteye.com/blog/855839)
方法3:把全局变量设置到AppDelegate中
例: 定义和使用一个全局变量"isLogin"
AppDelegate.h
@interface AppDelegate :UIResponder <UIApplicationDelegate>
@property (strong,nonatomic)UIWindow *window;
@propertyBOOL isLogin;
@end
AppDelegate.m
@implementation AppDelegate
@synthesize window =_window;
@synthesize isLogin;
@end
那么在其他的class里,则可以通过下列代码调用全局变量
AppDelegate *delegate=(AppDelegate*)[[UIApplicationsharedApplication]delegate];
delegate.isLogin=YES;
some developers recommend use singleton patter (ref link http://blog.csdn.net/kmyhy/article/details/7026511)
方法1:使用静态变量 (不推荐)
方法2: 使用singleton pattern (ref link: http://nice.iteye.com/blog/855839)
方法3:把全局变量设置到AppDelegate中
例: 定义和使用一个全局变量"isLogin"
AppDelegate.h
@interface AppDelegate :UIResponder <UIApplicationDelegate>
@property (strong,nonatomic)UIWindow *window;
@propertyBOOL isLogin;
@end
AppDelegate.m
@implementation AppDelegate
@synthesize window =_window;
@synthesize isLogin;
@end
那么在其他的class里,则可以通过下列代码调用全局变量
AppDelegate *delegate=(AppDelegate*)[[UIApplicationsharedApplication]delegate];
delegate.isLogin=YES;
相关文章推荐
- iOS全局变量设置
- ios中在AppDelegate设置全局变量
- ios设置全局变量
- IOS 设置全局变量
- iOS: 设置全局变量
- IOS中设置全局变量
- ios开发中全局变量设置和调用方法
- IOS中设置全局变量
- ios开发之 全局变量设置
- IOS中设置全局变量
- ios AppDelegate设置全局变量
- ios app应用中在AppDelegate设置全局变量
- IOS中设置全局变量
- iOS 通过AppDelegate设置全局变量【原创】
- Linux设置环境变量小结:设置永久变量&临时变量 全局变量&局部变量
- Mybatis中设置全局变量的方法示例
- 小程序之设置全局变量与改变全局变量的值 3ff8
- java 中如何设置可被所有类访问的全局变量
- js设置全局变量ajax中赋值
- IOS中全局变量与AppDelegate.h /.m 文件