我有一個文本框,當在文本框中鍵入內容並按下鍵盤上的「返回」時,鍵盤應該隱藏。但事實並非如此..返回按下時功能未運行
這裏是我使用的代碼:
import UIKit
class EditTableViewController: UITableViewController, UITextFieldDelegate {
var product: Product?
@IBOutlet weak var productImageView: UIImageView!
@IBOutlet weak var ProductDescriptionTextView: UITextView!
@IBOutlet weak var productTitleLabel: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
println("loaded")
productImageView.image = product?.image
productTitleLabel.text = product?.title
ProductDescriptionTextView.text = product?.description
}
override func viewWillDisappear(animated: Bool) {
product?.title = productTitleLabel.text
product?.description = ProductDescriptionTextView.text
product?.image = productImageView.image!
}
func textFieldShouldReturn(textField: UITextField) -> Bool // called when 'return' key pressed. return NO to ignore.
{
println("return")
return true
}
}
在控制檯中我得到的「裝」,但是當我按在文本框的回報,我不明白「返回「
怎麼回事?
您需要設置文本字段的委託,如果你還沒有在你的故事板 – Paulw11
這樣做您在隱藏鍵盤的'textFieldShouldReturn'函數中沒有任何代碼。它不會自動發生。如果這是你想要的,你需要隱藏它。 – rmaddy