【发布时间】:2015-05-07 22:34:43
【问题描述】:
我在对象库中添加了“搜索栏和搜索显示控制器”,并在我的 tableviewcontroller 中添加了必要的功能。 Tableviewcontroller 工作正常。但是当我点击搜索栏时,它给出了这个错误
“由于未捕获的异常 'NSInternalInconsistencyException' 导致应用程序终止,原因:'无法将标识符为 mysharedCell 的单元格出列 - 必须为标识符注册一个 nib 或类或连接情节提要中的原型单元格'”
我检查了小区标识符,没有问题。这是我的表格视图代码:
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()
}
我看不出有什么问题。我从另一个示例项目中正确复制了这些代码。我因此而错过了一些东西。该代码有什么问题?
【问题讨论】:
-
搜索显示控制器是否链接到委托?你也在课堂上调用 UISearchBarDelegate 例如
class TableviewController:PFQueryTableViewController, UISearchBarDelegate -
是的,我在 viewdidappaer 中调用了 searchbar.delegate = self 和 uisearchbardelegate。
-
我也遇到了同样的问题,代码似乎没问题。我通过转到主情节提要并检查插座并引用所有正确且没有重复的插座等来解决它。确保代理没有引用搜索栏,只是搜索显示控制器,因为这将显示新返回的表格视图。
-
看看我的网点:[link]tinypic.com/r/xpzi2r/8[link]这里有什么问题吗?
-
好吧,您的代理目前仅引用您的表格视图,而不是搜索显示控制器,您可能需要添加它以开始。如果您有时间看一下本教程/项目,这就是我最终使搜索栏工作的方式,(medium.com/swift-programming/…)我的错误是匆忙进入它而不是通过插座链接所有内容,这就是我的样子(tinypic.com/r/5cyjrd/8)
标签: ios uitableview swift parse-platform uisearchbar