0

I am creating a table view with custom cells.

Every cell has three buttons on it. I have added a view that should occupied the width and height from the cell, overlapping the three buttons. I am using it to create a swipeable cell.

The view that serves as overlay has white color background and opaque, but testing the app on the simulator, I have detected that when tapping on the cell, the buttons are lightly shown, please take a look at the picture.

enter image description here

What should I do to avoid the buttons to be seen. Why does it happen now if the overlay view is set as opaque. A second issue is when tapping on the cell, the left red bar, also a view, dissapear...

Thank you.

Community
  • 1
  • 1
mvasco
  • 4,965
  • 7
  • 59
  • 120
  • 1
    It seems the red bar (I assume it's a view) and your overlapping white view above the buttons are both suffering from the exact same problem. Are you adding them in storyboard or programmatically? Can you show some code? – Travis M. Mar 17 '15 at 19:04
  • @TravisM., both are added in the storyboard. – mvasco Mar 17 '15 at 19:11

2 Answers2

1

I believe this is a result of UITableViewCell's default selection styles. Let's try removing the default style and customizing it.

Try setting (depending on your implementation):

  1. cell.selectionStyle = UITableViewCellSelectionStyleNone; inside cellForRowAtIndexPath or
  2. self.selectionStyle = UITableViewCellSelectionStyleNone; in the Cell's custom subclass or
  3. "None" in Interface Builder under "Selection", if you're using IB.

Then, you can implement a custom selection style inside the UITableViewCell's custom class. Inside your initialization method, add something like:

self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.bounds]; self.selectedBackgroundView.backgroundColor = [UIColor lightGrayColor];

adamup
  • 1,508
  • 19
  • 29
0

The above answer will turn off cell selection highlighting completely and that may not be what you want.

After testing this out several times it appears what's happening is that when a cell is selected, iOS will convert the background color for all views on that cell to clearColor.

So the work around is to simply set the color of your on-cell views back to normal on selection:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let cell = tableView.cellForRowAtIndexPath(tableView.indexPathForSelectedRow()!) as! MyCell
    cell.MyViewOnMyCell.backgroundColor = UIColor.redColor()
}

See this question for other answers.

Community
  • 1
  • 1
William T.
  • 12,831
  • 4
  • 56
  • 53