ios - swift 和解析 : UISearchbar don't work

标签 ios uitableview swift parse-platform uisearchbar

我在对象库中添加了“搜索栏和搜索显示 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/

相关文章:

iphone - 为什么我的实例变量 nil 即使我正在设置它?

swift - 无法让文字转语音工作

ios - 创建另一个新节点时,SKShapeNode 中的节点重新出现

ios - Xamarin Forms iOS 状态栏文本颜色

ios - 冗余二进制文件上传。在 Softwareassets 上已经有构建版本为“1' for train ' 1.1.2”的二进制上传

ios - 为什么将 "viewWithTag"与 "dequeueReusableCellWithIdentifier"一起使用?

ios - 在我的 ios swift TableView 中创建 2 个不同高度的动态单元格原型(prototype)

ios - 如何制作具有动态高度的自定义 UITableViewCell?

swift - 如何判断UIButton类的选择状态?

ios - Frank(iOS验收测试框架)找不到Alamofire