Swift 3 | Xcode 8 datePicker mise à jour UItextField
Ce code permet de mettre à jour un textField
à l'aide de datePicker
pour Xcode 7 mais quand j'essaie de la mettre en œuvre dans Xcode 8 et Swift 3, l'application se bloque et jette un SIGABRT erreur dans l'AppDelegate.swift fichier. J'ai vérifier tous mes @IBs et je n'ai pas tous les divers autres connexions qui doivent être supprimés. Des conseils seraient grandement appréciés.
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet var eventStartText: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
eventStartText.delegate = self
//Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
//Dispose of any resources that can be recreated.
}
//MARK: TextField Delegate
func datePickerChanged(sender: UIDatePicker) {
let formatter = DateFormatter()
formatter.dateStyle = .full
eventStartText.text = formatter.string(from: sender.date)
print("Try this at home")
}
func textFieldDidBeginEditing(_ textField: UITextField) {
let datePicker = UIDatePicker()
textField.inputView = datePicker
datePicker.addTarget(self, action: (Selector(("datePickerChanged:"))), for: .valueChanged)
print("This Worked")
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
eventStartText.resignFirstResponder()
return true
}
//MARK: Helper Methods
func closekeyboard() {
self.view.endEditing(true)
}
//MARK: Touch Events
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
closekeyboard()
}
/*
//MARK: - Navigation
//In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//Get the new view controller using segue.destinationViewController.
//Pass the selected object to the new view controller.
}
*/
}
Voir raywenderlich.com/10209/my-app-crashed-now-what-part-1 pour savoir comment déboguer un crash. Si vous avez besoin d'aide, mise à jour de votre question avec plus de détails pertinents au sujet de l'accident (complète message d'erreur et le point de la ligne en réalité les causes de l'accident).
OriginalL'auteur Tom Bednarczyk | 2016-09-23
Vous devez vous connecter pour publier un commentaire.
Le problème est avec le
selector
de la syntaxe, de Swift 3, vous devez spécifier le premier nom de paramètre à l'intérieur deselector
, afin de changer votreselector
syntaxe comme celle-ci.Bienvenue mate 🙂
OriginalL'auteur Nirav D