使用PFQueryTableViewController和UISearchBar崩溃

时间:2015-12-08 10:42:39

标签: ios swift uitableview parse-platform uisearchbar

崩溃信息

  

UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:],/ BuildRoot / Library / Cache / com.apple.xbs / Sources / UIKit_Sim / UIKit-3512.29.5 / UITableView.m:6547   2015-12-08 16:29:01.851 EventAppTest [51390:3508575] ***由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法使用标识符EventCell对单元格出列 - 必须注册一个nib或类标识符或连接故事板'

中的原型单元格

但它会获取所有对象,因此单元格只有在点击搜索栏后才会崩溃?

似乎有什么问题?

    import UIKit
import Parse
import ParseUI

class EventListVC: PFQueryTableViewController,UISearchBarDelegate
{
    @IBOutlet var searchBar: UISearchBar!
    var searchString = ""
    var searchInProgress = false

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        tableView.estimatedRowHeight = tableView.rowHeight
        tableView.rowHeight = UITableViewAutomaticDimension
        searchBar.delegate = self

    }

override func queryForTable() -> PFQuery {
        let query = PFQuery(className: "Event")

        if searchInProgress {
            query.whereKey("eventTitle", containsString: searchString)
        }
        if self.objects!.count == 0 {

            query.cachePolicy = PFCachePolicy.CacheThenNetwork
        }

        query.orderByAscending("createdAt")
        return query

    }

   override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {

        // Configure the cell


        var cell = tableView.dequeueReusableCellWithIdentifier("EventCell", forIndexPath: indexPath) as? EventTableCell

        if cell == nil {
            cell = EventTableCell(style: UITableViewCellStyle.Default, reuseIdentifier: "EventCell")
        }

        cell!.titleLabel.text = object?.objectForKey("eventTitle") as? String



        return cell

    }

    func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
        searchString = searchText
        searchInProgress = true
        self.loadObjects()
        searchInProgress = false
    }


    func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
        searchBar.showsCancelButton = true
    }

    func searchBarSearchButtonClicked(searchBar: UISearchBar) {
        searchString = searchBar.text!
        self.loadObjects()
    }

    func searchBarCancelButtonClicked(searchBar: UISearchBar) {
        searchBar.text = nil
        searchString = ""
        self.loadObjects()
        searchBar.resignFirstResponder()
    }

2 个答案:

答案 0 :(得分:1)

知道了:)

来自这个

 var cell = tableView.dequeueReusableCellWithIdentifier("EventCell", forIndexPath: indexPath) as? EventTableCell

到这个

 var cell = tableView.dequeueReusableCellWithIdentifier("EventCell") as? EventTableCell

答案 1 :(得分:0)

根据您收到的错误,我认为您错过了指定单元格标识符。
您可以在Xcode右侧的属性窗口中找到它。 尝试将此图像中的“标识符”更改为下一个图像的值。

Try changing the "Identifier"


在这里,您将指定标识符

To This

希望这有帮助