1

UISearchControllerセルのカスタム スタイルを定義しようとしています (しかしできません) 。以下のコードを実行すると、EXC_BAD_INSTRUCTIONその行でエラーが発生しますcell.textlabel?.text。ここで完全に明らかな何かが欠けていますか?

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

    var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell!
    if (cell != nil) {
        cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "Cell")
    }
    if (tableView == self.searchDisplayController?.searchResultsTableView) {
        let data: AnyObject = self.searchResults.objectAtIndex(indexPath.row) as AnyObject
        println("searchresults: \(data)")
        cell.textLabel?.text = data.valueForKeyPath("name") as? String
        cell.detailTextLabel?.text = data.valueForKeyPath("placemark") as? String
    }
    return cell
}
4

1 に答える 1

1

何があっても、「Cell」という識別子を持つセルをデキューしています。代わりに、まず現在のテーブル ビューを確認してから、必要に応じて別のセル (別の識別子を持つ) をデキューします。

于 2014-10-17T15:24:07.277 に答える