当选择一个细胞,我希望它进行检查。我还希望检查的任何其他单元格都没有附件。不幸的是,我收到错误消息,提示我无法更改附件类型。那是因为我正在使用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)
}
查看API文档,visibleCells()
返回[AnyObject]
。由于雨燕类型安全,它不会让你设置accessoryType
上AnyObject
-它必须是一个UITableViewCell
。
尝试以下...
if let cells = tableView.visibleCells() as? [UITableViewCell] {
for oldCell in cells {
if oldCell.accessoryType == .Checkmark {
oldCell.accessoryType = .None
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句