[英]How to make keyboard stay when an alert box shows up?
I want to check if the value of a textfield is valid, if not, an alert box will pop up. 我想检查文本字段的值是否有效,如果没有,则会弹出一个警告框。 Here is my code: 这是我的代码:
- (IBAction) done: (id) sender{
if (!test) {
UIAlertView *alert = [[UIAlertView alloc]init....];
[alert show];
[alert release];
[textfield becomeFirstResponder];
}
else{
[sender resignFirstResponder];
//doing stuff;
}
}
Currently the alert box works fine, but when I dismiss the alert box, the focus doesn't get back to the textfield that I specified. 目前警报框工作正常,但当我关闭警报框时,焦点不会返回到我指定的文本字段。 Any idea where I did wrong? 知道我哪里做错了吗?
You can implement UIAlertView's -alertView:didDismissWithButtonIndex:
delegate method, which is called every time when alert view gets dismissed: 您可以实现UIAlertView的-alertView:didDismissWithButtonIndex:
委托方法,每当警报视图被解除时调用该方法:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
[textField becomeFirstResponder];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.