Ios UITableViewCell文本标签不显示为可选
我现在正在跟踪。我试图按照第10课的例子来做,我在下面的代码行收到了以下错误:Ios UITableViewCell文本标签不显示为可选,ios,uitableview,swift,Ios,Uitableview,Swift,我现在正在跟踪。我试图按照第10课的例子来做,我在下面的代码行收到了以下错误:后缀“?”的操作数应该有一个可选类型;类型为“UILabel” override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell: UITableViewCell = tableView.dequeueReusableCell
后缀“?”的操作数应该有一个可选类型;类型为“UILabel”
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(Storyboard.CellReuseIdentifier, forIndexPath: indexPath) as UITableViewCell
// Configure the cell...
let tweet = tweets[indexPath.section][indexPath.row]
cell.textLabel?.text = tweet.text // this line throws the error
cell.detailTextLabel?.text = tweet.user.name
return cell
}
但是,如果我删除?
,它会编译得很好。这与视频中的示例(使用?
编译)冲突。加上的文档显示,textLabel
是可选类型
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(Storyboard.CellReuseIdentifier, forIndexPath: indexPath) as UITableViewCell
// Configure the cell...
let tweet = tweets[indexPath.section][indexPath.row]
cell.textLabel.text = tweet.text // for some reason it wants me to treat the textLabel as a UILabel and not as an optional
cell.detailTextLabel?.text = tweet.user.name
return cell
}
有人能解释一下造成差异的原因吗 通过安装最新版本的Xcode(6.2版)解决了此问题。苹果正在更新其API wrt返回选项。苹果不断更改其Swift API,因此网络上有很多教程,有时甚至文档都会过时,直到更新为止。