选择单元格后,我希望对其进行检查。我还想要任何其他被检查的单元没有附件。不幸的是,我收到错误消息,说我无法更改accessoryType。那是因为我使用visibleCells()
来获取细胞吗?如何克服这个错误?
我试过不使用常量;我得到了同样的错误。我看了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)
}
答案 0 :(得分:2)
查看API documentation,visibleCells()
会返回[AnyObject]
。由于Swifts类型的安全性,它不允许您在accessoryType
上设置AnyObject
- 它必须是UITableViewCell
。
尝试以下方法......
if let cells = tableView.visibleCells() as? [UITableViewCell] {
for oldCell in cells {
if oldCell.accessoryType == .Checkmark {
oldCell.accessoryType = .None
}
}
}