arrays - 在 Swift 中从数组中选定的复选标记中删除字符串

标签 arrays swift uitableview tableview

我想通过复选标记删除未选定行中的数据。现在我可以将字符串附加到已检查的数组中。但我想从数组中删除哪些未经检查的数据。如何从数组中删除未经检查的数据?

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


    if(tableView == self.tableView_1) {

        if(tableView_1.cellForRow(at: indexPath)?.accessoryType == UITableViewCellAccessoryType.none) {
            tableView_1.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.checkmark

            checkedItemsForGender.append(cinsiyet[indexPath.row])

        }
        else{
            tableView_1.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.none

            checkedItemsForGender.remove(at: cinsiyet[indexPath.row]) // ??? ERROR 
        }

    }

最佳答案

你应该使用这个:

if let index = checkedItemForGender.index(of: cinsiyet[indexPath.row]) {
checkedItemsForGender.remove(at: index)
}

关于arrays - 在 Swift 中从数组中选定的复选标记中删除字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50116685/

相关文章:

c# - 将 'New' 数组从 VB.Net 转换为 C#

Java射击游戏删除子弹对象

c - 在C中对文本文件中的数据进行排序

ios - 将 Collection View 滚动到顶部

ios - 带有部分的快速表格 View 无法使用搜索栏

swift - UiTableview 在 iOS 10 中不更新 sizetofit 但在 iOS 11 中工作

ios - iPhone:默认隐藏 UITableView 搜索栏

ios - 从子 CollectionViewCell 访问父 tableViewCell

java - 字节数组是什么意思?

ios - 如何使用 Swift 4 验证数组中的特定键值