iOS/문제야문제
[Swift] UISearchController.searchBar 이벤트 안탈 때
용그무스
2022. 11. 30. 03:25
bookSearchController = UISearchController(searchResultsController: nil)
//searchController가 실행됐을 때 아래 배경을 어둡게 표시하는 여부
bookSearchController.obscuresBackgroundDuringPresentation = false
bookSearchController.searchBar.placeholder = "제목 또는 작가명 검색"
bookSearchController.searchBar.delegate = self
bookSearchController.searchResultsUpdater = self
bookSearchController.delegate = self
...
tableView.tableHeaderView = bookSearchController.searchBar
대충 서치바 코드 ..
navigationBar를 숨기고 Active될때마다 움직이지 않고 고정해서 쓰려고 tableHeaderView에 추가함
//이전뷰의 네비게이션바를 가리지 않고 보이게할라믄 true
definesPresentationContext = true
definesPresentationContext 값을 true로 하면 써치바를 탭했을 때 화면이 다 날라가버림(???????????)
기본값(false)로 두면
Application tried to present modal view controller on itself. Presenting controller is <UISearchController: 0x15f081c00>.'
오류가 남..
class SearchViewController: UIViewController {
테이블뷰 쓰려고 UITableViewController 상속받고있었는데 UIViewController를 상속받도록 수정해니깐 오류 안남.
이번에는 CancelButton 빼고 딜리게이트가 안먹음
//취소버튼 클릭
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
}
얘만 되고 온갖 searchBarText..어쩌고 이벤트가 안되는것임..
//테이블뷰 헤더에 써치바 추가
tableView.tableHeaderView = bookSearchController.searchBar
//네비게이션아이템에도 추가해야함
navigationItem.searchController = bookSearchController
테이블 헤더로 추가할래도 네비게이션아이템에 추가해주야하나벼~~~🖕