【发布时间】:2017-03-31 15:19:49
【问题描述】:
我有多行的 TableView,当我取消选择任何行时,我选择它们并将它们添加到标签文本中,我无法从标签文本中删除它
这是我的代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if tableView == categoryTable
{
let cell = self.categoryTable.dequeueReusableCellWithIdentifier("categoryCell") as! InquiryCategoryTableViewCell
let Category:CategoryDB = categoryData.objectAtIndex(indexPath.row) as! CategoryDB
print("Category = \(Category.category)")
cell.categoryName.text = "\(Category.category)"
cell.tintColor = color.UIColorFromRGB(0xCEEBFF)
categoryTable.allowsMultipleSelectionDuringEditing = true
categoryTable.setEditing(true, animated: false)
return cell
}
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if tableView == categoryTable
{
categoryList = categoryData[indexPath.row] as! CategoryDB
self.category_id = categoryList!.catg_id
print("Name = \(categoryList!.category)")
print("ID = \(self.category_id)")
categoryLabel.text! += "\(categoryList!.category), "
}
}
这是我得到的输出:
我首先选择了 3 行,它被附加到 Label.text 之后,我取消选择了行 Label.text 保持不变
谁能在这段代码中帮助我?
【问题讨论】:
-
您想在取消选择行时更新标签?
-
@UmairAfzal 是的
-
所以调用 didDeselectRowAtIndexPath 就像你使用 didSelectRowAtIndexPath 一样
-
@UmairAfzal 让我试试这个
标签: ios uitableview swift2 multipleselection uitableviewrowaction