swift3中tableview中的复选标记
如何在tableview中做多选勾选。我需要在tableview中选择多个复选标记,以及我需要选择哪些复选标记以将多个值放入标签中。 例PLAYER1,player2,player3在标签swift3中tableview中的复选标记
这里是我的代码
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return TypeOfAccountArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell
let cell:TypeofAccountCell=tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TypeofAccountCell
cell.Uertype_lbl.text=TypeOfAccountArray[indexPath.row]
cell.selectionStyle = UITableViewCellSelectionStyle.none;
cell.Uertype_lbl.font = UIFont(name:"Roboto-Regular", size:13)
cell.Uertype_lbl.adjustsFontSizeToFitWidth = true
if (selectedIndex == indexPath as NSIndexPath?) {
cell.checkmarkbtn.setImage(UIImage(named: "checkmark.png"),for:UIControlState.normal)
} else {
cell.checkmarkbtn.setImage(UIImage(named: "uncheckmark.png"),for:UIControlState.normal)
}
// Configure the cell...
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath as IndexPath, animated: true)
let row = indexPath.row
print(TypeOfAccountArray[row])
selectedIndex = indexPath as NSIndexPath?
self.Type_of_account_txt.text = (TypeOfAccountArray[row])
self.Type_account_view.isHidden = true
tableView.reloadData()
}
更改您的selectedIndex保持索引路径var selectedIndexes = [IndexPath]()
的阵列,在你的细胞XIB,上按钮设定对号图像中选择表示与正常状态uncheckmark图像,并使用下面的代码。
感谢您的响应..我需要将所有选定的值在标签/////例如...粉丝,教练,运动员,就像那样 – Agaram
你可以循环选定的索引来获得选定的文本。检查我更新的答案。 – Gamerlegend
多数民众赞成在工作很好,非常感谢如何使用逗号分隔符标记粉笔,教练,粉丝 – Agaram
您需要按照此步骤:
在didSelectRowAt,你需要添加和删除数组indexpath为多个复选标记。现在
-
,在你的cellForRowAtIndexPath需要检查当前
indexPath在于阵列。
if (![arrIndexPath containsObject: indexPath]) { // do something cell.checkmarkbtn.setImage(UIImage(named: "checkmark.png"),for:UIControlState.normal) }
不工作,我需要做多选,并将所选的值在标签 – Agaram
现在你的代码中发生了什么? – KKRocks
你可以发布答案 – Agaram