我在对象库中添加了“搜索栏和搜索显示 Controller ”,并在我的 tableviewcontroller 中添加了必要的功能。 Tableviewcontroller 工作正常。但是当我点击搜索栏时,它给出了这个错误
“由于未捕获的异常‘NSInternalInconsistencyException’而终止应用程序,原因:‘无法使具有标识符 mysharedCell 的单元格出列 - 必须为标识符注册一个 nib 或一个类,或者连接 Storyboard中的原型(prototype)单元格’”
我检查了单元格标识符,没问题。这是我的 TableView 代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("mysharedCell", forIndexPath: indexPath) as! MySharedTableViewCell
var object: PFObject = self.noteObjects.objectAtIndex(indexPath.row) as! PFObject
var likes:NSNumber = object["like"] as! NSNumber
cell.mySharedTitle?.text = object["title"] as? String
cell.mySharedText?.text = object["text"] as? String
if let x = object["date"] as? NSDate {
cell.mySharedDate?.text = getDateAsString(x)
}
else {
cell.mySharedDate?.text = "No date!"
}
cell.likesCount.text? = String("\(likes)")
return cell
}
这是我的搜索功能:
func searchBarTextDidEndEditing(searchBar: UISearchBar) {
// Dismiss the keyboard
searchBar.resignFirstResponder()
// Force reload of table data
self.fetchAllObjects()
self.fetchAllObjectsFromLocalDatastore()
}
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
// Dismiss the keyboard
searchBar.resignFirstResponder()
// Force reload of table data
self.fetchAllObjects()
self.fetchAllObjectsFromLocalDatastore()
}
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
// Clear any search criteria
searchBar.text = ""
// Dismiss the keyboard
searchBar.resignFirstResponder()
// Force reload of table data
self.fetchAllObjects()
self.fetchAllObjectsFromLocalDatastore()
}
我没有发现任何问题。我从另一个示例项目中正确复制了这些代码。因此我错过了一些东西。该代码有什么问题?
最佳答案
问题解决了。我在查询功能中错过了搜索控件。
代码:
if searchBar.text != "" {
query.whereKey("search_text", containsString: searchBar.text.lowercaseString)
}
关于ios - swift 和解析 : UISearchbar don't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30112798/