【发布时间】:2017-06-26 04:01:00
【问题描述】:
我想展示一个带有文本字段的 UIAlertController。这个完成了。但我不希望它成为第一响应者。有没有办法用文本框呈现 UIAlertController,但文本框不应该是第一响应者?
func showAlertData(data: String, at indexPath: IndexPath) {
let title = data
let alert = UIAlertController(title: renameDocumentString, message: renameDocumentMessageString, preferredStyle: UIAlertControllerStyle.alert)
alert.addTextField(configurationHandler: {(textField: UITextField) in
textField.text = title
textField.addTarget(self, action: #selector(self.textChanged(_: )), for: .editingChanged)
textField.addTarget(self, action: #selector(self.textDidBegin(_: )), for: .editingDidBegin)
})
let cancel = UIAlertAction(title: cancelString, style: UIAlertActionStyle.cancel, handler: { (_) -> Void in
alert.dismiss(animated: true, completion: nil)
})
let action = UIAlertAction(title: alertButtonOkString, style: UIAlertActionStyle.default, handler: { (_) -> Void in
if let textfield = alert.textFields?.first {
}
})
alert.addAction(cancel)
alert.addAction(action)
self.actionToEnable = action
action.isEnabled = false
self.present(alert, animated: true, completion: nil)
}
此代码将带有文本字段的 UIAlertController 呈现为响应者。我不想在展示 UIAlertController 时成为它的响应者。
【问题讨论】:
-
在当前完成块中辞职第一响应者?
-
我也尝试过。但它第一次显示键盘,然后隐藏它。但我第一次也不想要键盘。
-
您要编辑AlertController的UITextField的文本吗?
-
是的,一旦我们点击文本字段,键盘就会出现,而不是默认情况下
标签: swift uitextfield uialertcontroller