Я создал UIAlertController
с UITextfield
и UIPickerview
.
Когда я нажимаю кнопку для отображенияUIAlert UIPickerView
полностью смещен. Как я могу это исправить?
Вот мой код:
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return passwordCategory.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
passwordCategory[row]
}
func passwordAlert() {
let alert = UIAlertController(title: "type in some text", message: "", preferredStyle: .alert)
alert.addTextField { (passwordCategoryTextfield) in
passwordCategoryTextfield.placeholder = "e.g Business"
}
let pickerFrame = CGRect(x: 0, y: 0, width: 250, height: 300)
let picker = UIPickerView(frame: pickerFrame)
picker.delegate = self
picker.dataSource = self
alert.view.addSubview(picker)
alert.addAction(UIAlertAction(title: "add", style: .default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
let passwordInfo = alert.textFields?.first?.text
self.individualPasswordInformaiton.insert("\(passwordInfo ?? "")", at: 0)
print(self.individualPasswordInformaiton)
}))
alert.addAction(UIAlertAction(title: "cancel", style: .cancel, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
}))
self.present(alert, animated: true, completion: nil)
}