我有一个 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/