//类文件
//
// 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;
}