很簡單代碼:簡單的UITableView - 意外發現零
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
}
在cell.bookLabel.text線我得到這個:
fatal error: unexpectedly found nil while unwrapping an Optional value
的BookTableViewCell的定義是這樣的:
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
}
}
而bookLabel正確地連接在Storyboard中的Prototype單元格中。爲什麼我得到這個錯誤?
仍然不適合我。 – JohnVanDijk