ios - Using UISearchController to display search results and keyboard covers bottom rows/sections in UITableView -
there uisearchcontroller displays search results in uitableview split alphabetical sections , corresponding rows based on contacts name.
when there search result displays few contacts larger uitableview keyboard displayed, bottom rows , sections covered keyboard.
what best way increase uitableview content height when displaying filtered search result contacts @ bottom can scrolled , become visible user not covered ios keyboard anymore?
i using swift 3.1 , uisearchresultsupdating delegate updatesearchresults method display filtered results.
you need take care when keyboard appears/disappears , set tableview's contentinset
accordingly.
in tableviewcontroller class create 2 functions responders keyboard events:
func keyboardwillshow(notification: nsnotification) { if let keyboardsize = notification.userinfo?[uikeyboardframebeginuserinfokey] as? cgrect { let contentinsets = uiedgeinsets(top: 0, left: 0, bottom: keyboardsize.height, right: 0) self.tableview.contentinset = contentinsets } } func keyboardwillhide(notification: nsnotification) { self.tableview.contentinset = uiedgeinsets.zero }
and register/deregister responders in viewdidload
, deinit
:
override func viewdidload() { super.viewdidload() ... // register responders notificationcenter.default.addobserver(self, selector: #selector(self.keyboardwillshow), name: nsnotification.name.uikeyboardwillshow, object: nil) notificationcenter.default.addobserver(self, selector: #selector(self.keyboardwillhide), name: nsnotification.name.uikeyboardwillhide, object: nil) } deinit { notificationcenter.default.removeobserver(self) }
Comments
Post a Comment