Extension UITableView {
Func addnotifications () {
NotificationCenter.default.addObserver (Self, selector: #selector (Boardwillshow (not:)), Name: NSNotification.Name.UIKeyboardWillShow, Object:nil)
NotificationCenter.default.addObserver (Self, selector: #selector (Boarddidhide (not:)), Name: NSNotification.Name.UIKeyboardDidHide, Object:nil)
}
Func boardwillshow (not:nsnotification) {
If let UserInfo = not.userinfo {
If let Keyboardrect = Userinfo[uikeyboardframeenduserinfokey] as? CGRect {
Uiview.animate (withduration:0.25) {
Self.contentinset = uiedgeinsetsmake (0, 0, keyBoardRect.size.height, 0)
}
}
}
}
Func boarddidhide (not:nsnotification) {
Uiview.animate (withduration:0.25) {
Self.contentinset =. Zero
}
}
Func ' Deinit ' () {
NotificationCenter.default.removeObserver (self)
}
}
Use directly in the class you are using
Self.tableView.addNotifications ()
Func scrollviewwillbegindragging (_ Scrollview:uiscrollview) {
Self.view.endEditing (True)
}
UITableView keyboard override UITableViewCell input box workaround (Swift)