【发布时间】:2014-09-10 02:05:02
【问题描述】:
很简单的代码:
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 正确连接到情节提要的原型单元格中。为什么我会收到此错误?
【问题讨论】:
-
stackoverflow.com/a/39358940/5914117 也许你有 2 个或更多同名的视图控制器。
标签: ios uitableview swift