我创建了一个简单的应用,当您点击按钮时,第一次点击保存1
秒1
等等。所以,我试图检查第一次点击是否等于1,然后NSLog
,但它没有奏效。
这是我的代码:
-(IBAction)add:(id)sender
{
//Once the user click on the button it adds 1
static int num = 0;
num+=1;
//Save the number for key "saved and the number" ex: if number is 1 so for key is "saved 1"
NSString *dataa = [NSString stringWithFormat:@"%i", num];
NSString *fkey = [NSString stringWithFormat:@"saved %i", num];
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
[def setObject:dataa forKey:fkey];
[def synchronize];
}
-(IBAction)load:(id)sender
{
//load the data forkey "saved 1" wich will be '1'
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSString *loadd = [def objectForKey:@"saved 1"];
NSLog(@"%@",loadd);
//and here I failed, here I want to check if [def objectForKey:@"saved 1"] == '1'
//then NSLog@"Yes" but it NSLogs "NOO"
NSString *no = @"1";
if(loadd == no){
NSLog(@"YES");
}else{
NSLog(@"NOO");
}
}
那么这里的问题是什么?
先谢谢