Reputation: 5936
I’m trying to show an alert when a value greater than 200 is entered in my UITextField
, rcdAtIan.text
. I’ve tried this:
Self.rcdAtIan.text = self.circuit.rcdAtIan;
if (_rcdAtIan.text > @"200");{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Value Exceeded" message:@"Message here............." delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[alert show];
and then this:
Self.rcdAtIan.text = self.circuit.rcdAtIan;
if (self.circuit.rcdAtIan > @"200");{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Value Exceeded" message:@"Message here.........." delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[alert show];
}
but the alert is being shown when the view is loaded, rather than by my if
statement. I know what I’m trying to say — if (_rcdAtIan.text => 200 "show my alert");
— but I’m unsure of the correct syntax.
Upvotes: 0
Views: 69
Reputation: 14304
You're trying to perform an arithmetic comparison on 2 string values. What you need to do is ask:
if ([_rcdAtIan.text intValue] > 200) {...
Upvotes: 7
Reputation:
You can't compare strings like this (well, you can, but it doesn't make sense, since it performs a numerical comparison of the pointers which represent the strings, and it does not compare the contents of the strings). So, you may want to convert the strings to numerical values:
if ([self.circuit.rcdAtIan intValue] >= 200) {
// "200" or more has been entered
}
Upvotes: 4