簡體   English   中英

UITextField和UIPickerView

[英]UITextField and UIPickerView

當選擇UITextField時,是否可以顯示UIPickerView而不是鍵盤? Interface Builder中的每個選項都是某種鍵盤。

我想我可以以編程方式創建一個UIPickerView並在UITextField注冊一個touchUpInside事件時創建一個,然后告訴UITextField resignFirstResponder,但這看起來有點像黑客攻擊。

是否有“官方”或更“正確”的方式來做到這一點?

謝謝!

您可以實現此代碼並覆蓋默認行為(即顯示鍵盤):

#pragma mark -
#pragma mark UITextFieldDelegate methods

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
                                                    message:@"Bouh!"
                                                   delegate:nil 
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];
    return NO;
}

您可以展示自己的UIPickerView並做自己的事情,而不是顯示UIAlertView。

暫無
暫無

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

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