0
我使用Swift为我的代码添加了一个函数,它允许用户按下键盘上的返回来解除它,但它不工作,我不知道为什么。有人能带我走向正确的方向吗?为什么我的textField函数不起作用?
class SecondViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var item: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func addItem(sender: AnyObject) {
toDoList.append(item.text)
item.text = ""
NSUserDefaults.standardUserDefaults().setObject(toDoList, forKey: "toDoList")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
self.view.endEditing(true)
}
func textFieldShouldReturn(textField: UITextField!) -> Bool {
item.resignFirstResponder()
return true
}
}