ios - 如何使用 swift 中的自定义按钮选择表格 View 中的所有单元格?

标签 ios swift tableview core-animation grayscale

我有一个 tableView,其中所有单元格都包含一个 imageView。

通过单击 imageView,它将对其应用灰度。

我想使用栏按钮项目选择所有行。

如何实现这一目标任何人都可以帮助我。

这是我应用的图像变成黑白的代码。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    cellLabelSelected.text = "Card Number \(indexPath.row) Selected "
    print(" selected \(indexPath.row)")

    let cell = tableView.cellForRow(at: indexPath) as! 
    SecondTableViewCell

    guard let currentCGImage = images!.cgImage else { return }

        let currentCIImage = CIImage(cgImage: currentCGImage)

        let filter = CIFilter(name: "CIColorMonochrome")

        filter?.setValue(currentCIImage, forKey: "inputImage")

        filter?.setValue(CIColor(red: 0.6, green: 0.6, blue: 0.6), 
        forKey: "inputColor")

        filter?.setValue(1.0, forKey: "inputIntensity")

        guard let outputImage = filter?.outputImage else { return }

        let context = CIContext()

        if let cgimg = context.createCGImage(outputImage, from: outputImage.extent) {
            let processedImage = UIImage(cgImage: cgimg)
            print(processedImage.size)
            cell.cellImage.image = processedImage
    }

}     

func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {

    let cell = tableView.cellForRow(at: indexPath) as! SecondTableViewCell
     cell.cellImage.image = images
}

最佳答案

您可以在单击的 barButtonItem 上使用此方法:

func selectAllRows() {
    for section in 0..<tableView.numberOfSections {
        for row in 0..<tableView.numberOfRows(inSection: section) {
            tableView.selectRow(at: IndexPath(row: row, section: section), animated: false, scrollPosition: .none)
        }
    }
}

关于ios - 如何使用 swift 中的自定义按钮选择表格 View 中的所有单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55077608/

相关文章:

ios - Xcode 13 - "Button"标题没有消失

ios - 如何使用NSPredicate过滤数组,以使一个属性的值大于另一个属性的值?

swift - 如何在 Swift 中特化通用枚举

ios - 具有可变参数的通用类型别名

ios - 类型 'String.Index' 不符合协议(protocol) 'IntegerLiteralConvertible'

ios - 构建后 XCode iOS 颜色不匹配

ios - 如何使用 LockBox 删除钥匙串(keychain)存储

Javafx TableView 无法使用 FXML 进行编辑

swift - Firebase - 更改/删除子项时在所有 TableView 中显示重复的 TableView 行

ios - Swift:如何通过单击按钮 UITableViewCell 创建 UIActionSheet