当我选择多行时,它们应该添加到最大大小为 2 的数组中。
例如,我选择了名称为“A”和“B”的第 1 行和第 2 行。如果我取消选择“A”,我希望数组删除该值。
我选择 ["A", "B"]
我决定取消选择“A”,然后它应该从数组 ["B"] 中删除 A
var rows: [String] = []
func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
rows.append(values[indexPath.row])
}
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
rows.remove(values[indexPath.row])
}
extension Array where Element: Equatable {
func remove(e: Element) {
// Iam stuck here
}
}
最佳答案
这是你想要的:
extension Array where Element: Equatable {
mutating func remove(e: Element) {
if let i = self.indexOf(e) {
self.removeAtIndex(i)
}
}
}
关于ios - 取消选择表行删除索引行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38833111/