ios - Swift 如何通过按钮将我的 Tableview Cells accessoryType 重置为 .None

标签 ios swift uitableview accessorytype

我是 iOS 开发的初学者,我正在使用 swift。

我正在尝试编写一个简单的待办事项列表应用程序。完成后您可以在其中勾选项目,然后单击完成按钮一次将其全部删除。

Button 在将所选项目存储在数组中然后从主数组中删除后成功删除了这些项目

下面是“完成”按钮的代码

    @IBAction func btnDone(sender: AnyObject) {
    for i in selectedItems {
        items.removeAtIndex(i)
    }
    tableview.reloadData()
}

但问题是选中的勾没有去(或重置为.None)

我在以下链接中找到了一个对我来说很容易实现的解决方案: How to reset the tableview cells accessorytype to none on a click of a button?

但不幸的是在 Objective-C 中,有人可以翻译成 Swift 或提供类似的解决方案吗

最佳答案

请试试这个..

        @IBAction func btnDone(sender: AnyObject) {
            for (var section = 0, sectionCount = tableView.numberOfSections; section < sectionCount; ++section) {
                for (var row = 0, rowCount = tableView.numberOfRowsInSection(section); row < rowCount; ++row) {
                    var cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: section))
                    cell!.accessoryType = UITableViewCellAccessoryType.None
                    cell!.selectionStyle = UITableViewCellSelectionStyle.None
                }
            }
        }

关于ios - Swift 如何通过按钮将我的 Tableview Cells accessoryType 重置为 .None,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33836020/

相关文章:

ios - 当应用程序被终止(非事件)时,点击 Firebase 通知不起作用

ios - 如何仅提供回调函数或 block 而不是创建符合 UIPickerViewDelegate 的对象?

IOS 11 : Hide TableView does not working

iphone - 不同部分的自定义分组 UITable 标题

ios - 表格 View 单元格的圆角半径

ios - 如何跟踪 UICollectionView 索引

ios - UISearchController 中的 SearchBar 委托(delegate)不起作用

iphone - UITableView 标题问题

ios - 刷新关联域 iOS

ios - 如何在 sprite kit 游戏中改变重心?