Reputation: 1725
I am working on some simple form validation and need some assistance. Basically, I just need to make sure a UITextField
doesn't have a '0' or no value whatsoever (nil) when a user runs a simple calculation. If the field does contain either/or a label will be changed to notify the user. Here is my statement:
if ([abc.text isEqualToString:@"0"] || [time.text isEqualToString:nil]) {
self.123.text = @"Please enter a time";
} else { whatever }
Currently the 123 label is outputting NaN
if nothing is entered into the abc UITextField
.
Upvotes: 0
Views: 344
Reputation: 1271
if (![abc.text isEqualToString:@"0"] &&
![time.text == nil])
{
self.123.text = @"Please enter a time";
}
else
{
whatever
}
Upvotes: 1
Reputation: 3616
Replace [time.text isEqualToString:nil]
with [time.text isEqualToString:@""]
You are trying to compare string with a nil object, and since a nil object (nil) is not the same as an empty string (@""), it fails.
Upvotes: 1