2017-04-07 5 views
0

UITableViewで検索結果を表示し、アルファベットセクションと連絡先名に基づいて対応する行に分けて表示するUISearchControllerがあります。UISearchControllerを使用して検索結果とキーボードカバーを表示するUITableViewの下部行/セクション

キーボードが表示された状態でUITableViewよりも大きな接触を表示する検索結果がある場合、下部の行とセクションはキーボードでカバーされます。

フィルタリングされた検索結果を表示するときにUITableViewのコンテンツの高さを増やすには、下部の連絡先をスクロールしてユーザーに見せるようにするのがよいでしょう。

私はSwift 3.1とUISearchResultsUpdatingデリゲートをupdateSearchResultsメソッドで使用して、フィルタ処理された結果を表示しています。

答えて

1

キーボードが表示されたり消えたりするときには、tableViewのcontentInsetを適切に設定する必要があります。

override func viewDidLoad() { 
    super.viewDidLoad() 
    ... 

    // register the 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) 
} 
ViewDidLoaddeinitにレスポンダの登録を解除/

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 
} 

を、レジスタ:あなたのTableViewControllerクラスで

キーボードイベントへの応答として二つの機能を作成します

関連する問題