崩溃信息
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()
}
答案 0 :(得分:1)
知道了:)
来自这个
var cell = tableView.dequeueReusableCellWithIdentifier("EventCell", forIndexPath: indexPath) as? EventTableCell
到这个
var cell = tableView.dequeueReusableCellWithIdentifier("EventCell") as? EventTableCell
答案 1 :(得分:0)