ios - 如何过滤具有不同元素的数组?

标签 ios arrays swift uitableview

我有一个 TableView,我从中获取选定的 tableViewCell's数组中的值,但它不是所需的数组:

[<NSIndexPath: 0xc000000000200016\> {length = 2, path = 0 - 1}: "test1234", <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}: "Judson"]

我如何过滤它以获得 ["test1234","Judson"]

这是我使用的代码:

var selectedTextLabels = [NSIndexPath: String]()

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
    let cell = tableView.cellForRowAtIndexPath(indexPath) as! UsersTableViewCell
    if (cell.accessoryType == UITableViewCellAccessoryType.Checkmark){
        cell.accessoryType = UITableViewCellAccessoryType.None;
        selectedTextLabels[indexPath] = nil
    } else {
        cell.accessoryType = UITableViewCellAccessoryType.Checkmark;
        if (cell.accessoryType == UITableViewCellAccessoryType.Checkmark){
            if let text = cell.collegeNameLbl?.text {
                selectedTextLabels[indexPath] = text
            }
        }
    }
    print("\(selectedTextLabels)  outside")
}

最佳答案

由于 var selectedTextLabels = [NSIndexPath: String]() 是一个字典,您正试图检索它的 String 部分,即 values 你可以通过以下方式获得它们:

let values = Array(selectedTextLabels.values)

关于ios - 如何过滤具有不同元素的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34484084/

相关文章:

Javascript Caesar Cypher 只输出空字符串

ios - 用 UITableView 覆盖 UIView

ios - Lottie:无法获取带名称的动画

ios - 当应用程序进入后台时 AVAudioPlayer 不播放

c - 总是出现段错误

c - 如何在数组中显示多个具有不同十进制长度的数字,C 编程?

ios - 如何将图标上传到我的 app/xcode 4.2

ios - 无法从 iTunes 下载图像作品

ios - dataTaskWithRequest 因 302 重定向响应而崩溃 - Swift

ios - 将 ViewController 与场景一起呈现