1
votes

Instead of the default selectionStyle where the background view changes color I'm trying to just change the color of a UIView which I've added to the guideViewCell. However, when deselecting the cell or pressing another cell it doesn't seem to apply the clearColor on the previous indicatorImage. I've tried to set the selectedBackgroundView to clearColor however this will hide my custom border. What can I do in order to solve this issue?

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {


    let cell = tableView.dequeueReusableCellWithIdentifier("GuideCell", forIndexPath: indexPath) as! GuideViewCell
    cell.selectionStyle = UITableViewCellSelectionStyle.None



    return cell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var cell = tableView.cellForRowAtIndexPath(indexPath) as! GuideViewCell

    cell.indicatorImage.backgroundColor = UIColor.blackColor()
}

func tableView(tableView: UITableView, didDeSelectRowAtIndexPath indexPath: NSIndexPath) {
    var cell = tableView.cellForRowAtIndexPath(indexPath) as! GuideViewCell

    cell.indicatorImage.backgroundColor = UIColor.clearColor()
}
2
the problem is didDeSelectRowAtIndexPath ir should be didDeselectRowAtIndexPath - 0yeoj

2 Answers

1
votes

My solution was just to create new variable and save the indexPath

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var cell = tableView.cellForRowAtIndexPath(indexPath) as! GuideViewCell

    if (lastSelectedCell != nil) {
    var oldCell = tableView.cellForRowAtIndexPath(lastSelectedCell!) as! GuideViewCell
    oldCell.indicatorImage.backgroundColor = UIColor.clearColor()
    }
    lastSelectedCell = indexPath



    cell.indicatorImage.backgroundColor = UIColor.blackColor()
}
0
votes

You need to be sure the tableView delegate is set and the tableView allowsSelection or allowsMultipleSelection is set true.