IOS中设置全局变量
2015-05-22 13:41
393 查看
转:http://blog.csdn.net/totogogo/article/details/7355203
有几种方法
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设置全局变量
- ios中在AppDelegate设置全局变量
- iOS: 设置全局变量
- IOS 设置全局变量
- IOS中设置全局变量
- ios开发中全局变量设置和调用方法
- ios开发之 全局变量设置
- IOS中设置全局变量
- ios AppDelegate设置全局变量
- ios app应用中在AppDelegate设置全局变量
- iOS 通过AppDelegate设置全局变量【原创】
- IOS中设置全局变量
- iOS: 设置全局变量
- iOS开发之初:应该提出来的类.(网络任务管理/刷新控件/全局变量)
- Android用Application设置全局变量以及使用
- IOS设置导航栏全局的背景图片、导航栏title文字颜色大小、导航栏左右按钮的颜色。
- 防止重复提交要设置全局变量进行校验true false
- iOS 开发之全局特性设置
- centos JAVA环境变量设置(全局永久)