我认为这个方法
- (void)viewWillAppear:(BOOL)animated{
[textField1 becomeFirstResponder];}
然后当我打开这个视图时,我已准备好在textField1中编写键盘了,这没问题。
但是当我显示一个简单的警报视图时
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"ok!"
message:@"It's all right"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
当我在警报视图中按“确定”时,我的键盘消失并自动重新出现。为什么我有这种效果?我可以留下这种效果吗?
答案 0 :(得分:1)
尝试实现UITextFieldDelegate的方法
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
示例实施:
- (void)showAlertView
{
// declared as @property (nonatomic, assign) BOOL shouldHideKeyboard
self.shouldHideKeyboard = NO;
// code to show alert view here
// set the alert view's delegate to self
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
return self.shouldHideKeyboard;
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
self.shouldHideKeyboard = YES;
}