tableview를 inputview로 나타내는 텍스트 필드가 있습니다. 이 테이블 뷰에 2 가지를 추가하고 싶습니다.신속하게 테이블 뷰에 검색 막대 추가 프로그래밍 방식으로 검색 막대 추가
1) 검색 창을 추가하십시오.
2) 취소 버튼을 tableview 상단에 추가하십시오.
class enterYourDealVC: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate, UISearchResultsUpdating {
var tableView: UITableView = UITableView()
let searchController = UISearchController(searchResultsController: nil)
var dealAirports = [
airPorts(name: "Airport1", shortcut: "AP1")!),
airPorts(name: "Airport2", shortcut: "AP2")!)
]
var filteredAirports = [airPorts]()
//view did load
tableView = UITableView(frame: UIScreen.mainScreen().bounds, style: UITableViewStyle.Plain)
tableView.delegate = self
tableView.dataSource = self
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
toTextField.inputView = self.tableView
//here is my search function
func filterContentForSearchText(searchText: String, scope: String = "All") {
filteredAirports = dealAirports.filter { ap in
return ap.name.lowercaseString.containsString(searchText.lowercaseString)
}
tableView.reloadData()
}
}
문제는이 코드와 함께 검색하지 않습니다. 또한 검색 막대를 클릭하면 tableview가 닫히고 다시 viewcontroller로 돌아옵니다. 이 문제를 어떻게 해결할 수 있습니까?
및이 테이블 뷰에 취소 버튼을 어떻게 추가합니까?
UISearchController Apple 샘플 코드 : [Apple sample code] (https://developer.apple.com/libr) ary/ios/samplecode/TableSearch_UISearchController/소개/Intro.html) 구현하는 데 도움이됩니다. – Chandan
내가 객관적인 C를 알면 나에게 도움이 될 수있다. 나는 매우 복잡해 보인다. 코드를 계속 검토 할 것입니다. –