Ich habe eine TextField, wo ich eine PickerView putted erscheinen, wenn die Bearbeitung beginnt, wenn der Picker eine Alarmanzeige mit einem TextFeld in es mit zwei Schaltflächen ausgelöst und wann ausgelöst wird Diese AlertView erscheint mein Haupttextfeld endet Editing: aber wenn ich eine der Schaltflächen meiner AlertView schlagen, beginnt das Haupttextfeld zu bearbeiten, ich versuche herauszufinden, warum dies passiert aus Stunden, aber habe keine Ahnung, noch ist unten mein Code (nur Teil, der für mein Problem wirklich verantwortlich gedacht):textField beginEditing wird mehrmals aufgerufen, kann das Problem nicht verfolgen
class ProfileSettingTableViewController: UITableViewController, UITextFieldDelegate {
@IBOutlet var myextField: UITextField! // my main textField
override func viewDidLoad() {
super.viewDidLoad()
myTextField.delegate = self
tableView.tableFooterView = nil
tableView.tableHeaderView = nil
}
// the below function being called once i trigger a button from the picker
func showPickerViewAfterTextFieldEditingEnds {
var tField: UITextField!
func configurationTextField(textField: UITextField!)
{
textField.placeholder = "Enter here"
tField = textField
}
let alert = UIAlertController(title: "Enter Your Name", message: "", preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction = UIAlertAction(title: "Close", style: UIAlertActionStyle.Cancel) {
UIAlertAction in
self.myTextField.resignFirstResponder()
print("close button tapped")
}
alert.addTextFieldWithConfigurationHandler(configurationTextField)
// my below added functions (in the alert) is forcing my textField to start editing in odds attempts (when i hit the button first time then on third time then on 5th time and so on)
alert.addAction(cancelAction)
alert.addAction(UIAlertAction(title: "Done", style: UIAlertActionStyle.Default, handler:{ (UIAlertAction)in
self.myTextField.text = ""
self.myTextField.text = tField.text
self.myTextField.resignFirstResponder()
}))
self.presentViewController(alert, animated: true, completion: {
})
}
}
func textFieldDidBeginEditing(textField: UITextField){
let leftbutton: UIBarButtonItem = UIBarButtonItem(title: "Cancel", style: .Plain, target: self, action: nil)
let rightbutton: UIBarButtonItem = UIBarButtonItem(title: "Done", style: .Plain, target: self, action: nil)
self.navigationItem.leftBarButtonItem = leftbutton
self.navigationItem.rightBarButtonItem = rightbutton
}
func textFieldDidEndEditing(textField: UITextField){
self.navigationItem.leftBarButtonItem = nil
self.navigationItem.rightBarButtonItem = nil
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func nameEditingFinished(sender: AnyObject) {
}
@IBAction func selectNamePressed(sender: AnyObject) {
// my picker function which activates it self when the main TextField is begins editing... and from here the AlertView appears..
}
}
wenn jemand eine Ahnung, als bekäme lass es mich wissen, dass es für mich so nützlich sein wird