从数组中删除选定的索引

时间:2017-12-19 11:50:01

标签: ios arrays swift xcode

当我点击行时,我想出了如何放入所选元素的数组,我看到.checkmark。如果我第二次点击,我会看到勾选.none,但我如何删除我第二次点击的数组中的所选元素?

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let cell = tableView.cellForRow(at: indexPath)
    if indexPath.section == 0 {
        if (cell?.accessoryType == .checkmark) {
            cell?.accessoryType = .none
            print("deselect - \(titleOptions[indexPath.row])")

            // how to remove selectedIndex from array???
            selectedIndexArray....

            print("\(selectedIndexArray)")
        } else {
            cell?.accessoryType = .checkmark
            print("select - \(titleOptions[indexPath.row])")
            selectedIndexArray.append(titleOptions[indexPath.row])
            print("\(selectedIndexArray)")
        }
    }
}

0 个答案:

没有答案