0

、に200を超える値が入力されたときに、アラートを表示しようとしていUITextFieldますrcdAtIan.text。私はこれを試しました:

 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];

そしてこれ:

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];
    }

ifしかし、アラートは、私のステートメントではなく、ビューがロードされたときに表示されます。私は自分が何を言おうとしているのかを知っています— if (_rcdAtIan.text => 200 "show my alert");—しかし、正しい構文がわかりません。

4

2 に答える 2

7

2つの文字列値に対して算術比較を実行しようとしています。あなたがする必要があるのは尋ねることです:

if ([_rcdAtIan.text intValue] > 200) {...
于 2013-01-12T13:17:47.737 に答える
4

このように文字列を比較することはできません(文字列を表すポインタの数値比較を実行し、文字列の内容を比較しないため、できますが、意味がありません)。したがって、文字列を数値に変換することをお勧めします。

if ([self.circuit.rcdAtIan intValue] >= 200) {
    // "200" or more has been entered
}
于 2013-01-12T13:17:28.907 に答える