Я пытаюсь (но не могу) определить собственный стиль для ячейки UISearchController
. Выполнение приведенного ниже кода приводит к ошибке EXC_BAD_INSTRUCTION
на линии cell.textlabel?.text
. Я пропустил что-то совершенно очевидное здесь?Пользовательская ячейка для UISearchController
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
}
Вы проверили значение ключа «имя» не ноль? – DaSilva
Каков тип объекта в данных? Это быстрый тип или тип Obj-C? –
BTW, строка 5 должна быть 'if cell == nil {', а не 'if (cell! = Nil) {'. –