IBAction 戻り型のセレクター「go」が正しく応答しません。テキスト フィールドが空、つまり値が nil の状態でボタンがクリックされた場合、フローは「else」ではなく「if」部分を返す必要があります。しかし、ボタンを2回クリックするとうまくいきます。何が問題なのですか?
以下は、go セレクターを実装した実装ファイル、つまり ViewController.m のコードです。
@synthesize textField = _textField;
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
//Clear the text field
self.textField.text =nil;
}
NSString *s;
-(IBAction)go:(id)sender
{
[self.textField resignFirstResponder];
if (self.textField.text == nil)
{
s = [NSString stringWithFormat:@" Enter Your Name First " ];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Blank Field : "
message:s
delegate:self
cancelButtonTitle:@"OKAY"
otherButtonTitles:nil];
[alert show];
}
else
{
s = [NSString stringWithFormat:@"Hello %@ " , self.textField.text];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello "
message:s
delegate:self
cancelButtonTitle:@"Thanks"
otherButtonTitles:nil];
[alert show];
}
}
助けてください。前もって感謝します。