【问题标题】:Deleting string from selected checkmark in array at Swift从Swift数组中的选定复选标记中删除字符串
【发布时间】:2018-05-01 12:42:30
【问题描述】:

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

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 
        }

    }

【问题讨论】:

  • 你有两个账号thisthis吗?无论如何,您还没有从另一个帐户对question 进行更正。 :)

标签: arrays swift uitableview tableview


【解决方案1】:

你应该使用这个:

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

【讨论】:

    【解决方案2】:

    如下更新您的else 以修复errorindex out of bound exception 的可能性

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-29
      • 2018-10-19
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      • 2013-04-17
      相关资源
      最近更新 更多