我的單元格中顯示圖像視圖,其中顯示覆選標記圖標。swift table view將自定義複選標記添加到單元格並刪除前一個單元格的複選標記
我想要做的是當你觸摸一個單元格時,應該出現複選標記。我得到了這個工作,但我現在的問題是,我不能刪除前一個選定單元格的複選標記。 - 只能選擇一個單元格。
我試圖讓這個工作在didSelectRowAtIndexPath
但我不能正確的,所以我現在卡住了。
更新:
var selectedRow: NSIndexPath?
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: searchCityTableViewCell!
if (indexPath.section == 0) {
cell = tableView.dequeueReusableCellWithIdentifier("staticCityCell") as! searchCityTableViewCell
cell.titleLabel?.text = "Within \(stateName)"
}else if (indexPath.section == 1) {
cell = tableView.dequeueReusableCellWithIdentifier("cityCell") as! searchCityTableViewCell
let state = cities[indexPath.row]
cell.configureWithStates(state)
if indexPath == selectedRow {
cell.cityImage.select()
} else {
cell.cityImage.deselect()
}
}
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
let paths:[NSIndexPath]
if let previous = selectedRow {
paths = [indexPath, previous]
} else {
paths = [indexPath]
}
selectedRow = indexPath
tableView.reloadRowsAtIndexPaths(paths, withRowAnimation: .None)
}
http://stackoverflow.com/a/7172609/4475605 – Adrian