0
TextFieldがあります。ピッカーが表示されているときに編集が開始されたときに表示されるpickerViewと、2つのボタンでtextFeldこのalertViewは私の主なテキストフィールドの終わりです編集:私のAlertViewのボタンのどれかを押すと、メインのテキストフィールドが編集を開始します。なぜこれが何時から起こったのかわかりませんが、textField beginEditingが複数回呼び出されましたが、問題をトレースできません
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..
}
}
誰もが任意の手掛かりを得るなら、私に知らせてくださいよりも、それは私
のためにとても役に立つことでしょう。)私の問題のために実際に責任が思った部分