Ios TableView选择多行
我正在使用此代码选择Ios TableView选择多行,ios,tableview,Ios,Tableview,我正在使用此代码选择表视图中的特定行 tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none) 但如何选择多行,或将所有行设置为“选定” 在返回每个单元格之前,我尝试在cellForRowAtIndexPath中使用isSelected=true和isHighlighted=true,但没有效果。只需维护一个选定行的数组,并在cellForRowAtIndexPath中检查它们,然后返回单元格。确保您的表
表视图中的特定行
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
但如何选择多行,或将所有行设置为“选定”
在返回每个单元格之前,我尝试在
cellForRowAtIndexPath
中使用isSelected=true
和isHighlighted=true
,但没有效果。只需维护一个选定行的数组,并在cellForRowAtIndexPath
中检查它们,然后返回单元格。确保您的表允许多行选择,然后
tableView.isediting = true
tableView.allowsMultipleSelection = true
// select ALL rows in Section 0
for i in 0..<tableView.numberOfRows(inSection: 0) {
let iPath = IndexPath(item: i, section: 0)
tableView.selectRow(at: iPath, animated: false, scrollPosition: .none)
}
// select ALL VISIBLE rows
for iPath in tableView.indexPathsForVisibleRows! {
tableView.selectRow(at: iPath, animated: false, scrollPosition: .none)
}
// select rows 2, 4 and 6
for i in [2, 4, 6] {
let iPath = IndexPath(item: i, section: 0)
tableView.selectRow(at: iPath, animated: false, scrollPosition: .none)
}
//选择节0中的所有行
对于0中的i..将此添加到viewDidLoad方法中,tableView.allowsMultipleSelection=True就是这样。我可以用tableView选择不同的行。选择行(最好你应用代码,然后我们就可以讨论更新我,是它被挽救了还是你仍然被困在这个问题上。J.Doe我的答案有效吗?