我正在尝试使用Swift创建UITableViewCell类型变量,以下是我的代码:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return dwarves.count }
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier(simpleTableIdentifier)! as UITableViewCell
if (cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: simpleTableIdentifier)
}
cell.textLabel?.text = dwarves[indexPath.row]
return cell
}
在第七行的if (cell == nil),它给了我一个错误,即UITableViewCell类型的值永远不可能为nil,因此不允许比较。它不能被替换为if (!cell)。我该如何修复这些代码?