我需要在 UIAlertController 出现后立即选择文本字段的文本。但是,我在标准 UITextField 中选择文本的方式在这里不起作用。
这是我尝试过的,但我似乎无法让它发挥作用。
let ac = UIAlertController(title: "Rename", message: nil, preferredStyle: .Alert)
ac.addTextFieldWithConfigurationHandler({
[] (textField: UITextField) in
textField.selectedTextRange = textField.textRangeFromPosition(textField.beginningOfDocument, toPosition: textField.endOfDocument)
textField.text = "filename.dat"
})
ac.addAction(UIAlertAction(title: "CANCEL", style: .Cancel, handler: nil))
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: {
[] Void in
// do something
}))
dispatch_async(dispatch_get_main_queue(), {
self.presentViewController(ac, animated: true, completion: nil)
})
有任何想法吗?