In my app I have a UITableView
, which includes in its first cell a UITextView
and in the other cells just UILabel
s.
How can I dismiss the keyboard after typing something in the UITableView
? I want to dismiss it anytime I tap on the other cells or scroll the tableview.
You can use the UITableViewDelegate
which conforms to the UIScrollViewDelegate
to implement:
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
dismissKeyboard()
}
func dismissKeyboard(){
self.view.endEditing(true)
}
//Add to viewDidLoad:
var tapGesture = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
tableView.addGestureRecognizer(tapGesture)
//Or since you wanted to dismiss when another cell is selected use:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
dismissKeyboard()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.