0

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 Answers2

1

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.

carlos16196
  • 706
  • 1
  • 7
  • 10
0

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

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
  • It doesn't work because didselectRowAtIndexPath delegate called when cell's content view touched, When I add Button, it becomes subview of cell's content view. – Mustafa Sait Demirci Apr 10 '15 at 15:45
  • Mustafa it was working in my sample. You can download that [sample from here](https://www.dropbox.com/s/exg521g76cbgac3/ObjcTest.zip?dl=0) – Inder Kumar Rathore Apr 11 '15 at 04:42