I have a custom switch
UICustomSwtich: UISlider
downloaded from here
How it works
UICustomSwitch overwrite this touch events to work as it have to work:
- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
Good tests
UICustomSwitch works perfectly in any UIView, even a UIScrollView. The three touches events are called properly when it have to be called.
Bad works
Here’s my problem. I have a static UITableView designed from StoryBoard with this hierarchy:
UITableView> UITableViewCell> UIView > UICustomSwitch
In this scenario:
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
This function is called properlly
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
When I move the thumb less than the length of the bar, the thumb remains at the same point I left it (the problem).
When I move the thumb to left and right (rises the end of the bar) the two methods are called (very strange behavior, isn’t it?).
I looked for the answer finding similar problems with different solutions, but any good for my problem.
Why touch events sometimes reaches my UICustomSwitch and sometimes not? And why the events of ended and trackingWithTouch but not the began?
Thanks in advance.
I obtained a solution implementing all (less one commented) touch and track events:
When the control is out of a table works with normal methods. When is inside a table, sometimes exit by cancelled methods and sometimes by ended methods. In any case, I obtained the correct behavior.
But there is a question unresolved.. Why
UITableVieworUITableViewCellcancellUITouchevents ofUICustomSwitch?