我正在尝试验证我的uitextfield,它只允许数字不为0(零)。这次检查每次都失败了吗?调试resultsString ='0'(我输入零),因为我试图让它失败,但它不会失败。
NSString *resultingString = budgetField.text;
if(resultingString == @"0" || [resultingString length] == 0){
[AppHelpers showAlert:@"Dude!" withMessage:@"Don't be cheap I know you have more than a $1"]; //never gets in here.
return;
}
if(resultingString == @"0" || [resultingString length] == 0){
[AppHelpers showAlert:@"Dude!" withMessage:@"Don't be cheap I know you have more than a $1"]; //never gets in here.
return;
}
答案 0 :(得分:2)
要比较两个字符串,您可以这样做:
[string1 isEqualToString:string2]
编辑: 这将比较实际的字符串而不是字符串的指针。
答案 1 :(得分:1)
==
运算符比较指针。您想要比较字符串的值,因此请使用isEqualToString:
等方法。
答案 2 :(得分:1)
使用“==”表示值,而不是字符串:
([resultingString intValue] == 0 || [resultingString length] == 0)