那我就不知道为什么了,我没有你用的那么复杂,我把我的用法贴出来给你看看
存
+(void)saveUser:(NSString *)account userID:(int)UserID passwd:(NSString *)passwd
{
[UD setObject:@{@"account" : account, @"userID":[@(UserID) stringValue], @"passwd" : passwd} forKey:@"loginInfo"];
[UD synchronize];
}取
+(NSString *) account
{
return [[UD objectForKey:@"loginInfo"] valueForKey:@"account"];
}就这样就行了
存
+(void)saveUser:(NSString *)account userID:(int)UserID passwd:(NSString *)passwd
{
[UD setObject:@{@"account" : account, @"userID":[@(UserID) stringValue], @"passwd" : passwd} forKey:@"loginInfo"];
[UD synchronize];
}取
+(NSString *) account
{
return [[UD objectForKey:@"loginInfo"] valueForKey:@"account"];
}就这样就行了
解决方案 »
- 没有交99刀,可以用ipad测试xcode写的应用吗,求指教
- 多个scrollview怎么继承一个UIScrollViewDelegate并响应
- XCode4.3.2安装后找不到Interface builder,请问XCode4.3.2如使用Interface builder?
- 主程序和动态库共享全局变量问题
- 90后MM聊夜店生态圈:夜店App不是SNS 而是O2O
- 使用 UIImageJPEGRepresentation block
- libimobiledevice获取app的png图标
- 关于开发者账号和黑苹果
- oc,为什么简单的方法继承会报错?
- 请问可以用Video toolbox 实现网络视频的转码吗? flv->mp4
- 刚学object-c 有点混乱 求指点
- 数据为空时,tableview的显示
不知这篇文章能不能解决你的疑惑
//注册默认设置
NSDictionary *defaultValues = [NSDictionary dictionaryWithObjectsAndKeys: [[NSNumber alloc] initWithBool:NO], @"currency", [[NSNumber alloc] initWithBool:YES], @"dailyNotification", nil];
[userDefaults registerDefaults:defaultValues];
[userDefaults setValue:[[NSNumber alloc] initWithInt:0] forKey:@"dailyNotification"];
BOOL flag = [userDefaults boolForKey:@"dailyNotification"];
NSLog(@"flag = %d", flag);
[userDefaults removeObjectForKey:@"dailyNotification"];
flag = [userDefaults boolForKey:@"dailyNotification"];
NSLog(@"flag = %d", flag);你的代码:
NSDictionary *defaultValues = [NSDictionary dictionaryWithObjectsAndKeys:0,@"currency",YES,@"dailyNotification", nil];
[userDefaults registerDefaults:defaultValues];实际就是:
NSDictionary *defaultValues = [NSDictionary dictionaryWithObjectsAndKeys:0];
[userDefaults registerDefaults:defaultValues];NSDictionary dictionaryWithObjectsAndKeys需要的参数是对象,这个时候,0与nil是等价的。