Abbastanza semplice:Semplice UITableView a Swift - inaspettatamente trovato il codice zero
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
}
Sulla linea cell.bookLabel.text ottengo questo:
fatal error: unexpectedly found nil while unwrapping an Optional value
Il BookTableViewCell è definita in questo modo:
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
}
}
E bookLabel è correttamente collegato in una cella Prototype nello Storyboard. Perché ricevo questo errore?
Ancora non funziona per me. – JohnVanDijk