IBAction 返回类型的选择器“go”没有正确响应。如果在文本字段为空的情况下单击按钮,即其值为 nil ,则流程应返回“if”部分而不是“else”。但是当我第二次单击该按钮时它工作正常。可能是什么问题?
下面是实现文件的代码,即 ViewController.m,我在其中实现了 go 选择器。
@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];
}
}
请帮忙。提前致谢。