斯威夫特 4
private var positionArray = ["All", "QB", "RB", "WR", "TE", "K", "DE", "OL", "LB", "EDGE", "DT", "CB", "S"]
// 1 在您的文本字段中添加一个委托
tf.delegate = self
// 2 扩展你的 UITextfield 委托
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
// to avoid keyboard
textField.resignFirstResponder()
// add action sheet
let alert = UIAlertController(title: LocalString("draft_title"), message: LocalString("draft_select_position"), preferredStyle: .actionSheet)
for i in positionArray {
alert.addAction(UIAlertAction(title: i, style: .default , handler:{ (UIAlertAction)in
textfield.text = i
self.view2021Draft?.positionSelected(isSelected: true, positionValue: textfield.text ?? "")
}))
}
alert.addAction(UIAlertAction(title: "Dismiss", style: .cancel, handler:{ (UIAlertAction)in
self.view2021Draft?.positionSelected(isSelected: false, positionValue: textfield.text ?? "")
}))
//uncomment for iPad Support
alert.popoverPresentationController?.sourceView = self.view
self.present(alert, animated: true, completion: {
print("completion block")
})
return false
}