【发布时间】:2017-09-07 13:23:01
【问题描述】:
我无法通过使用在堆栈溢出中搜索的复选标记将多个选定的行文本放入数组中,但无法实现它,谁能帮助我如何获取数组中的文本?
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return productName.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "filterSelectionCell", for: indexPath) as! FilterSelectionCell
activityIndicator.stopAnimating()
activityIndicator.hidesWhenStopped = true
tableDetails.isHidden = false
cell.brandProductName.text = productName[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
if let cell = tableView.cellForRow(at: indexPath as IndexPath) {
if cell.accessoryType == .checkmark{
cell.accessoryType = .none
}
else{
cell.accessoryType = .checkmark
}
}
}
这是图片
【问题讨论】:
-
从数据源(model)而不是从单元格(view)获取数据。将
selected属性添加到模型并相应地在cellForRow中设置附件类型。要获取所有选定的单元格,只需按selected == true过滤数据源数组。
标签: ios uitableview swift3