iOS 定义类将请求的数据放到类中方便全局调用
2013-12-10 10:36
204 查看
//类文件
//
// User.h
// MJK
//
// Created by ming on 13-12-6.
// Copyright (c) 2013年 eric.gao. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface User : NSObject
@property(assign,nonatomic)NSString *userId;//用户id
@property(strong,nonatomic)NSString *userName;//用户名
@property(strong,nonatomic)NSString *userPassword;//密码
@property(strong,nonatomic)NSString *userImageUrl;//用户照片
@property(strong,nonatomic)NSString *userCommonArea;//常在地区
@property(strong,nonatomic)NSString *userEmail;//邮箱
@property(strong,nonatomic)NSString *userHeadImgURL;//用户头像
@property(strong,nonatomic)NSString *userNickName;//昵称
@property(strong,nonatomic)NSString *userRoleName;//
@property(strong,nonatomic)NSString *userSex;//性别
@property(strong,nonatomic)NSString *userSign;//签名
@property(strong,nonatomic)NSString *userStatus;//状态
@property(strong,nonatomic)NSString *userMobile;//手机号
+(User*)shareUser;
-(void)getuserInfoFromDictionary:(NSDictionary*)dic;
@end
=====================================================================
//
// User.m
// MJK
//
// Created by ming on 13-12-6.
// Copyright (c) 2013年 eric.gao. All rights reserved.
//
#import "User.h"
@implementation User
static User *shareuser = nil; //第一步:静态实例,并初始化。
+(User*)shareUser
{
{
@synchronized (self)
{
if (shareuser == nil)
{
shareuser= [[self alloc] init];
}
}
return shareuser;
}
}
-(id)init
{
self=[super init];
if (self) {
}
return self;
}
-(void)getuserInfoFromDictionary:(NSDictionary*)dic{
Dictionary2Object(dic,@"id",self.userId);
Dictionary2Object(dic,@"userName",self.userName);
Dictionary2Object(dic,@"userPassword",self.userPassword);
Dictionary2Object(dic,@"userImageUrl",self.userImageUrl);
Dictionary2Object(dic,@"userCommonArea",self.userCommonArea);
Dictionary2Object(dic,@"userEmail",self.userEmail);
Dictionary2Object(dic,@"userHeadImgURL",self.userHeadImgURL);
Dictionary2Object(dic,@"userNickName",self.userNickName);
Dictionary2Object(dic,@"userRoleName",self.userRoleName);
Dictionary2Object(dic,@"userSign",self.userSign);
Dictionary2Object(dic,@"userStatus",self.userStatus);
Dictionary2Object(dic, @"userMobile", self.userMobile);
Dictionary2Object(dic, @"userSex", self.userSex)
}
@end
=以上是类文件=================================================
登陆页面引用#import "User.h"头文件
NSDictionary*personnalInfo=[object objectForKey:@"record"];//将personnalInfo的字典数据存到user中
[[User shareUser]getuserInfoFromDictionary:personnalInfo];
NSLog(@"%@",[User shareUser].userId);
=以上存数据到user中=================================================
获取人员信息页面引用#import "User.h"头文件
self.userName.text=[User shareUser].userName;//获取人员信息
if([[User shareUser].userSex isEqualToString:@"男"])
{
[self.manBtn setBackgroundImage:[UIImage imageNamed:@"025_dian_1"] forState:UIControlStateNormal];
[self.womanBtn setBackgroundImage:[UIImage imageNamed:@"025_dian_2"] forState:UIControlStateNormal];
}
else
{
[self.manBtn setBackgroundImage:[UIImage imageNamed:@"025_dian_2"] forState:UIControlStateNormal];
[self.womanBtn setBackgroundImage:[UIImage imageNamed:@"025_dian_1"] forState:UIControlStateNormal];
}
isdel=@"男";
if(![[User shareUser].userMobile isKindOfClass:[NSNull class]])
self.telPhone.text=[User shareUser].userMobile;
if (![[User shareUser].userEmail isKindOfClass:[NSNull class]]) {
self.email.text=[User shareUser].userEmail;
}
if (![[User shareUser].userCommonArea isKindOfClass:[NSNull class]]) {
self.address.text=[User shareUser].userCommonArea;
}
if (![[User shareUser].userSign isKindOfClass:[NSNull class]]) {
self.talk.text=[User shareUser].userSign;
}
//
// User.h
// MJK
//
// Created by ming on 13-12-6.
// Copyright (c) 2013年 eric.gao. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface User : NSObject
@property(assign,nonatomic)NSString *userId;//用户id
@property(strong,nonatomic)NSString *userName;//用户名
@property(strong,nonatomic)NSString *userPassword;//密码
@property(strong,nonatomic)NSString *userImageUrl;//用户照片
@property(strong,nonatomic)NSString *userCommonArea;//常在地区
@property(strong,nonatomic)NSString *userEmail;//邮箱
@property(strong,nonatomic)NSString *userHeadImgURL;//用户头像
@property(strong,nonatomic)NSString *userNickName;//昵称
@property(strong,nonatomic)NSString *userRoleName;//
@property(strong,nonatomic)NSString *userSex;//性别
@property(strong,nonatomic)NSString *userSign;//签名
@property(strong,nonatomic)NSString *userStatus;//状态
@property(strong,nonatomic)NSString *userMobile;//手机号
+(User*)shareUser;
-(void)getuserInfoFromDictionary:(NSDictionary*)dic;
@end
=====================================================================
//
// User.m
// MJK
//
// Created by ming on 13-12-6.
// Copyright (c) 2013年 eric.gao. All rights reserved.
//
#import "User.h"
@implementation User
static User *shareuser = nil; //第一步:静态实例,并初始化。
+(User*)shareUser
{
{
@synchronized (self)
{
if (shareuser == nil)
{
shareuser= [[self alloc] init];
}
}
return shareuser;
}
}
-(id)init
{
self=[super init];
if (self) {
}
return self;
}
-(void)getuserInfoFromDictionary:(NSDictionary*)dic{
Dictionary2Object(dic,@"id",self.userId);
Dictionary2Object(dic,@"userName",self.userName);
Dictionary2Object(dic,@"userPassword",self.userPassword);
Dictionary2Object(dic,@"userImageUrl",self.userImageUrl);
Dictionary2Object(dic,@"userCommonArea",self.userCommonArea);
Dictionary2Object(dic,@"userEmail",self.userEmail);
Dictionary2Object(dic,@"userHeadImgURL",self.userHeadImgURL);
Dictionary2Object(dic,@"userNickName",self.userNickName);
Dictionary2Object(dic,@"userRoleName",self.userRoleName);
Dictionary2Object(dic,@"userSign",self.userSign);
Dictionary2Object(dic,@"userStatus",self.userStatus);
Dictionary2Object(dic, @"userMobile", self.userMobile);
Dictionary2Object(dic, @"userSex", self.userSex)
}
@end
=以上是类文件=================================================
登陆页面引用#import "User.h"头文件
NSDictionary*personnalInfo=[object objectForKey:@"record"];//将personnalInfo的字典数据存到user中
[[User shareUser]getuserInfoFromDictionary:personnalInfo];
NSLog(@"%@",[User shareUser].userId);
=以上存数据到user中=================================================
获取人员信息页面引用#import "User.h"头文件
self.userName.text=[User shareUser].userName;//获取人员信息
if([[User shareUser].userSex isEqualToString:@"男"])
{
[self.manBtn setBackgroundImage:[UIImage imageNamed:@"025_dian_1"] forState:UIControlStateNormal];
[self.womanBtn setBackgroundImage:[UIImage imageNamed:@"025_dian_2"] forState:UIControlStateNormal];
}
else
{
[self.manBtn setBackgroundImage:[UIImage imageNamed:@"025_dian_2"] forState:UIControlStateNormal];
[self.womanBtn setBackgroundImage:[UIImage imageNamed:@"025_dian_1"] forState:UIControlStateNormal];
}
isdel=@"男";
if(![[User shareUser].userMobile isKindOfClass:[NSNull class]])
self.telPhone.text=[User shareUser].userMobile;
if (![[User shareUser].userEmail isKindOfClass:[NSNull class]]) {
self.email.text=[User shareUser].userEmail;
}
if (![[User shareUser].userCommonArea isKindOfClass:[NSNull class]]) {
self.address.text=[User shareUser].userCommonArea;
}
if (![[User shareUser].userSign isKindOfClass:[NSNull class]]) {
self.talk.text=[User shareUser].userSign;
}
相关文章推荐
- 数据请求(写在一个JS文件里,方便调用)
- iOS新机首次安装 app,请求网络权限“是否允许使用数据”
- iOS_21团购_发送请求获取【点评】数据
- 关于ajax请求数据,并将数据赋值给全局变量的一些解决方法
- iOS请求数据AFNetworking
- 【iOS开发】SDWebImage框架,加载图片,失败之后,居然直接跳过不再去请求网络数据了?
- ios 后台数据请求AFNetwork常遇见的1016错误与3840错误的解决方法
- RxJava + Retrofit+okhttp 封装,包含对相同格式请求数据、相同格式返回数据处理,显示 Material Design 加载 dialog,文件上传下载进度展示、全局异常捕捉。
- IOS 请求数据解析 XML 和 JSON
- 虽然操作麻烦,但终于成功了——fiddler抓取android http请求包,极大方便了android调用webservice的调试。
- iOS 网络请求数据缓存
- 树状结构中展示的数据从数据库取出后进行再次封装使其方便UI层调用
- iOS 网络编程 ASI 发送请求数据
- iOS从webservice上请求数据,第一次接触怎么搞?
- iOS 10 的坑:新机首次安装 app,请求网络权限“是否允许使用数据”
- Jquery Ajax学习实例3-向WebService发出请求,调用方法返回数据
- iOS网络编程-ASIHTTPRequest小例子-数据请求队列
- ios NSURLRequest NSMutableURLRequest 数据请求
- iOS- 利用AFNetworking去管理从聚合数据上面请求到的数据
- iOS项目之Swift新闻App(二)—网络数据请求和添加TableHeader