2017-04-07 2 views
0

UITableView의 검색 결과를 알파벳순 섹션과 연락처 이름을 기반으로 해당 행으로 나누어 표시하는 UISearchController가 있습니다.UISearchController를 사용하여 UITableView의 검색 결과 및 키보드 맨 아래 행/섹션을 표시합니다.

키보드가 표시된 상태에서 UITableView보다 큰 연락처가 몇 개 표시되는 검색 결과가있는 경우 하단 행과 섹션이 키보드로 덮여 표시됩니다.

필터링 된 검색 결과를 표시 할 때 UITableView 콘텐츠 높이를 늘리는 가장 좋은 방법은 하단의 연락처를 스크롤하여 사용자가 볼 수있게하여 더 이상 iOS 키보드에 의해 보호되지 않도록 할 수 있습니다.

나는 스위프 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 클래스에서

키보드 이벤트에 조치로 두 가지 기능을 만들