1

I have a simple table view which looks like this enter image description here

Each button overflows some part to next cell (part of requirement).

I want that overflowing button's click event. How to get that ?

By default its taking it as cell click rather than button click if i click on that overflowing part.

I have created a dummy code which changes button color on click, so it is easy for someone to try it out. same layout.

Thanks

EDIT

Below is the original image , what i am trying to do , for simplicity sake i scaled it down to a button Lets assume req is u cant change height and cant play around table view separator

enter image description here

Aishwat Singh
  • 4,331
  • 2
  • 26
  • 48

3 Answers3

1

Subclass UITableView and override hitTest:withEvent: and figure out if point is within the frame of one of the buttons. Return the button if the point is within the frame or just return [super hitTest:point withEvent:event] otherwise.

You can use CGRectContainsPoint and [UIView convertRect/Point:to/fromView:] to make calculation easier.

hitTest:withEvent: is a way for the system to ask the outermost view who will receive the event at a given location.

yusuke024
  • 2,189
  • 19
  • 12
1

You have to implement 'tableView:heightForRowAtIndexpath:` method and return greater value than it has now. Your cells don't have enough height to display buttons fully, and because of that some part of your button hides behind of next cell. You can be convinced easily by checking "Clip subviews" checkbox of your Cell Prototype in the interface builder, and if you will see that buttons will be clipped.


EDIT

Check this: https://github.com/arturdev/test

enter image description here

arturdev
  • 10,884
  • 2
  • 39
  • 67
  • i know , but overflow is a part of requirement , its mentioned, and its coming on next cell , bcoz clip is false – Aishwat Singh Apr 19 '16 at 07:16
  • Than you can do following. Hide tableView separator by setting "Separator" to "None" from storyboard for your tableView. Then, make cell's height bigger, so the buttons could displayed completely, then add your custom separator at the same Y position that you have now. For custom separator you can add a UIView with 1pt height and set background color to lightGrayColor. – arturdev Apr 19 '16 at 07:21
  • actual requirement is a container view over there , which has one more table view , basically a spinner kinda , but i simplified problem statement and made it as button, so this approach is not doable – Aishwat Singh Apr 19 '16 at 07:24
  • Then if you can post here a screenshot of actual requirement, we can tell you how to do that.. I'm pretty sure, that `hitTest:withEvent` solution is too much for this job and you can have more simple and beautiful solution. – arturdev Apr 19 '16 at 07:32
  • @aishwatsingh See edited answer. I think this is more beautiful, simple and clean solution ;) – arturdev Apr 19 '16 at 11:36
  • @aturdev whooa, its great. Exactly what i was looking for. Other solution was to use pop over but it had issue while scrolling. simple `addsubview` :D thanks limbo ;) – Aishwat Singh Apr 19 '16 at 14:09
1

Make UITableView seperator to None. draw 1 or 2 pixel height label with black background color in cell.

Make cell selection style none in cellForRowAtIndex.

cell.selectionStyle =  UITableViewCellSelectionStyle.None

Manage proper autolayout or autoresizing mask.

Just tried with your code.

Download from link

Image

enter image description here

Hasya
  • 9,792
  • 4
  • 31
  • 46