ios - 取消选中 "checked cell"

标签 ios xcode uitableview swift

我创建了一个简单的表格 View ,您可以在其中检查已完成的任务。该特定属性的代码如下所示:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    let mySelectedCell: UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
    mySelectedCell.accessoryType = UITableViewCellAccessoryType.Checkmark
    mySelectedCell.tintColor = UIColor.blackColor()


}

问题是,一旦选中这些单元格,我就无法取消选中它们。有谁知道这个属性是如何添加的?

任何关于如何继续的想法将不胜感激。

编辑:我现在知道需要一个 if 语句,但我不知道如何检查我的单元格是否已被检查。

最佳答案

如果您只想为了美观而进行简单的断断续续...

if (mySelectedCell.accessoryType = UITableViewCellAccessoryType.Checkmark) {
    mySelectedCell.accessoryType = UITableViewCellAccessoryType.None
}
else {
    mySelectedCell.accessoryType = UITableViewCellAccessoryType.Checkmark
}

如果你想基于属性来做到这一点......

if (!myValue[indexPath.row].value) { // if the BOOL is NO
    mySelectedCell.accessoryType = UITableViewCellAccessoryType.None
}
else {
    mySelectedCell.accessoryType = UITableViewCellAccessoryType.Checkmark
}

关于ios - 取消选中 "checked cell",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27592800/

相关文章:

Xcode 4.3.1 : Doesn't show me line of code when: Terminating app due to uncaught exception

ios - 使用ubuntu服务器在jenkins上构建xcode项目

ios - 使用 swift 连接 UIImageView 以查看 Images.xcassets 中的 Controller 显示图像

swift - 新手 - 无法访问 TableView 函数且无法加载 tableView

iphone - UISearchBar + didSelectRowAtIndexPath + cellForRowAtIndexPath

iOS:使用 XCUIDevice().siriService 点击按钮

ios - AVAudioSession outputVolume 未在 iOS 9+ 上更新

ios - 使用 UIImagePickerControllerDelegate 获取照片的图像 URL

ios - 将表格单元格委托(delegate)给其他表格 View

ios - 如何在 Swift 中拆分 JSON 字符串?