0
我试图挂钩一个搜索栏,上面是我的表视图中的视图中:搜索栏不一致错误(Swift)?
//Outlet for the table search bar/controller
@IBOutlet var searchBar: UISearchBar!
var searchController = UISearchController(searchResultsController: nil)
var searchBar_optional = false
//Function for when the search button is triggered
@IBAction func searchButtonPressed(sender: UIBarButtonItem) {
if(searchBar_optional == false){
tableView.contentInset = UIEdgeInsets(top: barView.bounds.size.height-30, left: 0.0, bottom: 0.0, right: 0.0)
searchBar_optional = true
}
else if (searchBar_optional){
tableView.contentInset = UIEdgeInsets(top: barView.bounds.size.height-78, left: 0.0, bottom: 0.0, right: 0.0)
searchBar_optional = false
}
}
var dataArray = [MainTableViewCell]()
var filteredArray = [MainTableViewCell]()
var shouldShowSearchResults = false
func filterContentForSearchText(searchText: String, scope: String = "All"){
filteredArray = dataArray.filter{ cell in
if((cell.fileName.text?.containsString(searchText.lowercaseString)) == true){
return true
}
else if((cell.fileDescription.text?.containsString(searchText.lowercaseString)) == true){
return true
}
else if((cell.fileCategory.text?.containsString(searchText.lowercaseString)) == true){
return true
}
else if((cell.fileType.text?.containsString(searchText.lowercaseString)) == true){
return true
}
else{
return false
}
}
tableView.reloadData()
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
filterContentForSearchText(searchBar.text!)
}
func configureSearchController() {
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
}
它当搜索按钮被按下,使搜索栏可见的视图下移。然而,当我按下搜索栏,这个错误弹出:
*** Assertion failure in -[UISearchResultsTableView
dequeueReusableCellWithIdentifier:forIndexPath:],
/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-
3512.60.7/UITableView.m:6573
2016-08-02 13:13:05.001 References[22478:14561725] *** Terminating app due
to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to
dequeue a cell with identifier MainTableCell - must register a nib or a
class for the identifier or connect a prototype cell in a storyboard'
我为我的细胞小区标识为MainTableCell,所以这就是为什么它说,在错误。任何想法是怎么回事?
你有你的注册用的UITableView笔尖文件:
请试试这个用替换此? – tek3
@ tek3是的。表格视图工作正常,当我在搜索栏内点击时发生唯一的错误 –
看看这个链接是否有帮助。 http://stackoverflow.com/questions/14207142/assertion-failure-when-using-uisearchdisplaycontroller-in-uitableviewcontroller – tek3