[英]How to make text field “become first responder” in UIAlertView
我在UIAlertView中有兩個文本字段。 我希望第二個成為第一個響應者,這樣用戶就不必點擊它。 顯示警報視圖后,我有以下代碼:
[textField becomeFirstResponder];
唯一的問題是它不起作用。 第一個文本字段中包含了typer。 有任何想法嗎? 謝謝你的幫助。
嘗試將焦點設置到UIAlertView中的密碼字段時我遇到了同樣的問題(我預先填充了用戶名)。 我不得不使用委托方法:
- (void)didPresentAlertView:(UIAlertView *)alertView {
UITextField *textField = [alertView textFieldAtIndex:0];
[textField becomeFirstResponder];
}
如果我在willPresentAlertView上嘗試它或者當我創建alertView時,它只能在didPresentAlertView上運行。 我希望這有幫助。
標記的答案是正確的,我只是添加了一些與我上面的評論相關的更多說明,這里是代碼; 在使用它之前測試該字段是否存在並查看索引0:
if ([alertView textFieldAtIndex:0])
{
UITextField *textfield = [alertView textFieldAtIndex:0];
[textfield becomeFirstResponder];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.