IOS:iPad 上的 AlertView 和键盘问题

发布于 2024-11-16 10:54:04 字数 686 浏览 1 评论 0原文

我在一个视图中有这个方法

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

我的键盘会消失并自动重新出现。为什么我有这个效果?我可以保留这个效果吗?

I have in a view this method

- (void)viewWillAppear:(BOOL)animated{
[textField1 becomeFirstResponder];}

then when I open this view I have my keyboard ready to write in textField1, and it's all right.

but when I show a simply alert view

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"ok!" 
                                                        message:@"It's all right"
                                                       delegate:nil 
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
    [alertView show];
    [alertView release];

when I press "ok" in alert view my keyboard disappears and reappears after automatically. Why I have this effect? Can I leave this effect?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紙鸢 2024-11-23 10:54:04

尝试实现 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;
}

Try implementing UITextFieldDelegate's method

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField

Example implementation:

- (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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文