Einfaches UITableView in Swift - unerwartet null gefunden

Ziemlich einfacher Code:

func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
    return 1
}

func tableView(tableView:UITableView!, numberOfRowsInSection section:Int) -> Int {
    return 5
}


func tableView(tableView:UITableView!, cellForRowAtIndexPath indexPath:NSIndexPath!) -> UITableViewCell! {
    let cell: BookTableViewCell = BookTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "BookCell")
    println("ip: \(indexPath.row)")
    cell.bookLabel.text = "test"

    return cell
}

In der Zeile cell.bookLabel.text erhalte ich Folgendes:

fatal error: unexpectedly found nil while unwrapping an Optional value

Die BookTableViewCell ist folgendermaßen definiert:

class BookTableViewCell: UITableViewCell {

    @IBOutlet var bookLabel: UILabel

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

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

        // Configure the view for the selected state
    }

}

Und bookLabel ist korrekt mit einer Prototypzelle im Storyboard verbunden. Warum erhalte ich diesen Fehler?

Antworten auf die Frage(10)

Ihre Antwort auf die Frage