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

5
  • Does clicking just the table view cell perform a segue? Commented Apr 19, 2016 at 7:04
  • Set Tag for Each cell's Button. And then in Button Action check for tag and perform the action respectively. Commented Apr 19, 2016 at 7:11
  • @rigdonmr no segue , Balaji but it wont go to Button Check , checking tag comes later Commented Apr 19, 2016 at 7:14
  • hasya, arturdev , actual requirement is somewhat like this , edited post , i scaled down it to a button Commented Apr 19, 2016 at 7:44
  • You have to make clear your question earlier. Well, That is another tableview you need to make animate like scroll down which you could do it easily. best luck. Commented Apr 19, 2016 at 7:50

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

6 Comments

i know , but overflow is a part of requirement , its mentioned, and its coming on next cell , bcoz clip is false
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.
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
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.
@aishwatsingh See edited answer. I think this is more beautiful, simple and clean solution ;)
|
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.

5 Comments

let me give it a try
i am still not able to get hitTest , possible for u to make a commit in git ? i know its a lot to ask, or can i use touchesBegan:withEvent:
@aishwatsingh I've opened the pr github.com/aishwat/test/pull/1 check it out
Thanks , this works in current scenario, vl try it in actual case. Still looking for some cleaner approach , if i dont find anything better by tomorrow , vl accept this as answer
BTW I know that this is not up to you, but I think a better design approach is to use UIPicker and present it as a popover on iPad.
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.