2014-09-03 91 views
0

这是我的代码。我升级到Xcode-beta 7后出现奇怪的编译错误

 var indexPath = self.tableView.indexPathForCell(cell) 
     self.tableView.beginUpdates() 
     self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation:.Automatic) 
     self.tableView.endUpdates() 

我得到了以下编译错误:

Use of unresolved identifier 'Automatic'

我试过UITableViewAnimation.Automatic。但也失败了。

它有什么问题?谢谢。

+0

尝试'UITableViewRowAnimation。 Automatic' – 2014-09-03 13:36:07

回答

1

错误消息是误导性的。 在Xcode中6测试版7,indexPathForCell()返回可选,所以你必须解开 或使用有条件分配:

if let indexPath = self.tableView.indexPathForCell(cell) { 
    self.tableView.beginUpdates() 
    self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic) 
    self.tableView.endUpdates() 
} 

(请注意,调用begin/EndUpdates是不是真的有必要,如果只有一行 是更新。)