簡體   English   中英

iOS:iPad上的AlertView和鍵盤問題

[英]IOS: problem with AlertView and keyboard on iPad

我認為這種方法

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

當我在警報視圖中按“確定”時,鍵盤會消失,並在自動出現后重新出現。 為什么會有這種效果? 我可以離開這個效果嗎?

嘗試實現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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM