在Xcode 6.1.1中运行以下代码
override func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(
TableViewValues.identifier, forIndexPath: indexPath) as UITableViewCell
cell.textLabel.text = items[indexPath]
return cell
}
有报错:
"UILabel?" does not have a member named 'text'
原因分析:
swift刚出来,语法也在不断优化和变化中,所以语法格式可能有所调整。
cell的textLabel是个Optional,所以要用"!" 强制unwrap成UILabel:
cell.textLabel!.text = items[indexPath]
文章评论