2014-12-03 54 views
0

分配給「accessoryType」,我希望它進行檢查。我也想要其他任何被檢查的單元沒有附件。不幸的是,我收到錯誤信息,說我無法更改accessoryType。那是因爲我使用visibleCells()來獲取細胞嗎?我如何克服這個錯誤?不能在UITableViewCell中

我曾嘗試不使用常量;我得到了同樣的錯誤。我看了UITableView & UITableViewCell類的引用,但我沒有看到任何可以幫助我的東西。我的備份計劃是使用Picker View,但我更喜歡使用Table View,因爲它的設計。

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    let cell = tableView.cellForRowAtIndexPath(indexPath) 
    let cells = tableView.visibleCells() 
    for oldCell in cells { 
     if(oldCell.accessoryType == UITableViewCellAccessoryType.Checkmark) { 
      oldCell.accessoryType = .None //Cannot assign to 'accessoryType' in 'oldCell' 
     } 
    } 
    cell!.accessoryType = .Checkmark 
    day = cell!.textLabel!.text! 
    self.tableView.deselectRowAtIndexPath(indexPath, animated: true) 
} 

回答

2

望着API documentationvisibleCells()回報[AnyObject]。由於雨燕類型安全,它不會讓你設置accessoryTypeAnyObject - 它必須是一個UITableViewCell

請嘗試以下...

if let cells = tableView.visibleCells() as? [UITableViewCell] { 
    for oldCell in cells { 
    if oldCell.accessoryType == .Checkmark { 
     oldCell.accessoryType = .None 
    } 
    } 
}