2014-09-03 98 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是不是真的有必要,如果只有一行 是更新。)