0
이것이 내 코드이므로 complexTable이라는 테이블 뷰를 위임 한 뷰 컨트롤러가 있습니다. 어떤 이유로 UISearchController는 self.complexTable
대신 self.tableView
을 조회합니다. 내보기 컨트롤러 위임자와 일치하도록 테이블보기를 설정할 수있는 위치를 찾을 수 없습니다. 이 코드를 이해하는 또 다른 중요한 설명은 manager
변수입니다. 다른 Array<SidebarComplex>
개체를 보유하고 있습니다.UISearchController가 잘못된 테이블 뷰를 취함
self.searchDisplayController.table = self.complexTable
것은하지만 난 그런 아무것도 찾을 수 없습니다 :
궁극적으로,이 같은 다소있는 명령을하고 싶습니다. 또한 검색 창에 대한 일부 대리인은 스토리 보드에 선언되어 있지만 참조하는 내용을 실제로 이해하지 못합니다.
import UIKit
let COMPLEX_IDENTIFIER = "SideBarComplexCell"
class SideBarViewController: UIViewController {
@IBOutlet var complexTable: UITableView!
var complexSearchResults: Array<SidebarComplex> = []
var manager = SidebarManager()
override func viewDidLoad() {
super.viewDidLoad()
complexTable.dataSource = self
complexTable.delegate = self
complexTable.tableFooterView = UIView()
manager.fetch()
self.searchDisplayController!.delegate = self
self.complexTable.reloadData()
}
}
extension SideBarViewController: UISearchBarDelegate, UISearchDisplayDelegate{
func filterContentForSearchText(searchText: String) {
self.complexSearchResults = self.manager.complexArray.filter({(complex: SidebarComplex) -> Bool in
return complex.name!.lowercaseString.rangeOfString(searchText.lowercaseString) != nil
})
}
func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchString searchString: String?) -> Bool {
self.filterContentForSearchText(searchString!)
return true
}
}
extension SideBarViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = complexTable.dequeueReusableCellWithIdentifier(COMPLEX_IDENTIFIER) as! SideBarComplexCell
var complexArray: Array<SidebarComplex>
if complexTable == self.searchDisplayController!.searchResultsTableView {
complexArray = self.complexSearchResults //This is never called even when I search.
} else {
complexArray = self.manager.complexArray
}
if complexArray.count > indexPath.section {
let complex = complexArray[indexPath.section]
cell.setupData(complex)
cell.setupUI()
}
return cell
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
if complexTable == self.searchDisplayController!.searchResultsTableView{
print("took from search") //Never called!!
return self.complexSearchResults.count
} else {
print("took from all")
return self.manager.complexArray.count
}
}
}
perffffect! 덕분에, 내가 할 수있는 한 해결할 수 있습니다 : D 조 – Eyzuky