Swift:UISearchResultsTableView

时间:2015-11-11 16:31:47

标签: swift

我有一个在我的项目中工作的表视图控制器,附加到继承自UITableViewController的自定义类。此表视图使用可重用的单元格。

一切正常,我想添加一个搜索功能,所以我将“搜索栏和搜索显示控制器”对象添加到了故事板。

现在,当我点击搜索栏时出现以下错误:

*** Assertion failure in -[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:],
     

/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UITableView.m:6547       2015-11-11 16:26:24.212 Footy Vault [10420:2922226] ***由于未捕获的异常'NSInternalInconsistencyException'而终止应用,   原因:'无法使用标识符Cell将单元格出列 - 必须注册   标识符的笔尖或类或连接原型单元格   故事板'

我没有在TableView中更改我的可重用单元格标识符,所以我不知道在哪里进行故障排除。

任何帮助都会非常感谢!

编辑:索引路径代码中的行的单元格:

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    // **Method wide variables**

    let context = self.fetchedResultsController.managedObjectContext
    let sortDescriptor = NSSortDescriptor(key: "selectedTeam", ascending: false)
    let fetchRequest = NSFetchRequest(entityName: "UserSettings")
    fetchRequest.sortDescriptors = [sortDescriptor]
    let frcu = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
    cell.accessoryType = .None
    let currentItem = teamsArray[indexPath.row]
    let teamName = currentItem.valueForKey("TeamName")!

    do {
        try  frcu.performFetch() //Fetch all entries in the UserSettings core data entity
        for us in frcu.fetchedObjects! as! [UserSettings] //For each item in the data entity, retrieve it as an object of type UserSettings and place into an array
        {
            let str = us.valueForKey("selectedTeam") as! String //Retrieve the name of the team from the entry in the data entity
            if selectedTeams.contains(str){
            } else {
                selectedTeams.append(str)
            }
            let cellText = currentItem.valueForKey("TeamName") as! String //Retrieve the name of the team from the entry in the array
            if str == cellText { //If the two team names match
                cell.accessoryType = .Checkmark //Apply a checkmark to the cell
            }
        }
    } catch {
        // Do something in response to error condition
    }

    cell.textLabel!.text = currentItem.valueForKey("TeamName") as? String //Set the text label of the cell to the team name
    cell.detailTextLabel!.text = currentItem.valueForKey("CurrentDiv") as? String //Set the detail text label of the cell to the team division

    return cell

}

由于

0 个答案:

没有答案