Can't seem to read UITextField value correctly
I am 开发者_如何转开发trying to verify that my uitextfield, which only allows numbers isn't 0 (zero). This check fails every time? When debugging resultingString = '0'( I type in zero ) as I am trying to make it fail, but it doesn't fail.
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;
}
To compare two strings you would do this:
[string1 isEqualToString:string2]
Edit: This would compare the actual strings and not the pointers to the strings.
Use "==" for values, not strings:
([resultingString intValue] == 0 || [resultingString length] == 0)
The ==
operator compares pointers. You want to compare the values of the strings instead, so use a method like isEqualToString:
.
精彩评论