Classe de registre UITableViewCell personnalisée dans Swift

Dans mon application, j'ai à remplir le tableau sur la base de la matrice. Le tableau utilise personnalisé UITableViewCell. Tout fonctionne bien, la table est remplie. Puis-je ajouter de Recherche de Contrôleur d'Affichage à ma UITableViewController, pas d'écrire du code pour gérer la recherche, il suffit d'ajouter le contrôleur. Lorsque vous exécutez l'application, la table est toujours rempli.Mais si j'ai essayer de cliquer sur la barre de recherche, j'obtiens l'erreur:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier CitiesListCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

J'essaie de l'ajouter à ma viewDidLoad fonction dans UITableViewController ligne:

self.tableView.registerClass(MyCell.classForCoder(), forCellReuseIdentifier: kCellIdentifier)

De lancer l'application et obtenir immédiatement l'erreur:

fatal error: unexpectedly found nil while unwrapping an Optional value

En ligne cell.cellMyCity.text = cellText

Ce que je fais mal?

C'est ma Coutume UITableViewCell classe:

import UIKit

class MyCell: UITableViewCell {

@IBOutlet var cellMyImage: UIImageView
@IBOutlet var cellMyCity: UILabel
@IBOutlet var cellMyCountry: UILabel
@IBOutlet var cellMyTemp: UILabel

init(style: UITableViewCellStyle, reuseIdentifier: String!) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
}

override func awakeFromNib() {
    super.awakeFromNib()
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

}
}

C'est le code pour la cellule:

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

    var cell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier, forIndexPath: indexPath) as MyCell!

    if cell == nil {
        cell = MyCell(style: UITableViewCellStyle.Default, reuseIdentifier: kCellIdentifier)
    }

    let cellText: String? = dataWeatherSelectedCity[indexPath.row].name as  String
    println("Строка: \(cellText)")
    cell.cellMyCity.text = cellText

    let cellSubtitle: String? = dataWeatherSelectedCity[indexPath.row].country as String
    cell.cellMyCountry.text = cellSubtitle

    cell.cellMyImage.image = UIImage(named: "Blank52")

    var currentCityWeatherURL = "http://api.wunderground.com/api/\(self.myAPI.kWundergroundApiKey)/conditions/lang:RU/q/zmw:\(self.dataWeatherSelectedCity[indexPath.row].zmv).json"

    var fullObservation:NSDictionary = self.myAPI.jsonParsingWeather(currentCityWeatherURL)
    var currentObservation:NSDictionary = fullObservation.valueForKey("current_observation") as NSDictionary

    var currentWeather = self.myAPI.parsingOneCityCurrentCondition(currentObservation)       
    cell.cellMyImage.image = currentWeather.image
    cell.cellMyTemp.text = currentWeather.temp
    return cell
}

Propriété dans TableViewCell:
Classe de registre UITableViewCell personnalisée dans Swift
Classe de registre UITableViewCell personnalisée dans Swift
Classe de registre UITableViewCell personnalisée dans Swift

Table sans self.tableView.registerClass(MyCell.classForCoder(), forCellReuseIdentifier: kCellIdentifier) ou self.tableView.registerClass(MyCell.self, forCellReuseIdentifier: kCellIdentifier):

Classe de registre UITableViewCell personnalisée dans Swift

source d'informationauteur Alexey Nakhimov