Disabling touch interaction of Spaces between Custom table view cell

65 views Asked by At

I use custom cells of subclassing UITableViewCell in a table view. And There must be space between cells. I succesfully add the space with adding a subview that I called SpaceView into the content view. But When I touched the spaceView, it is perceived as I touched the cell. And didSelectRow method called. I tried to set spaceView's UserInteractionEnabled==NO. But It doesn't work.

So my question is; Is this the right way I used to add space between cells ? Should I try to add cells for making the space ? or If its the right way, How can I prevent calling "didSelectRowAtIndexPath" method when I touched spaceView ?

2

There are 2 answers

2
Inder Kumar Rathore On

Make your spaceView as UIButton (I guess it's UIView right now)

When you add UIButton that touch will be consumed by the button thus touch won't be passed to it's parent.

OR

I'm not sure if it will work or not, you can add tap gesture to your spaceView

0
carlos16196 On

like Inder said below, u can use an UIButton to solve the issue.

1) in your custom cell: at the bottom of your custom cell add a blank UIButton with the height u actually need between cells, and customize its background color according to your needs.

2) in cellforrowatindexpath: disable button of each cell. (or you can also do that in Interface Builder of previous step)

result: u have a clear disabled button that will appear as required space between cells.