Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:19:40+00:00 2026-06-17T12:19:40+00:00

I have a custom switch UICustomSwtich : UISlider downloaded from here How it works

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:19:40+00:00Added an answer on June 17, 2026 at 12:19 pm

    I obtained a solution implementing all (less one commented) touch and track events:

    #pragma - touches
    
    - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
    {
        [super touchesBegan:touches withEvent:event];
    
        LOG(@"touches began");
    
        m_touchedSelf = NO;
        on = !on;
    }
    
    //- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    //{
    //    [super touchesMoved:touches withEvent:event];
    //    
    //    LOG(@"touches moved");
    //    
    //}
    
    - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
    {
        [super touchesEnded:touches withEvent:event];
    
        LOG(@"touches ended");
    
        if (!m_touchedSelf)
        {
            [self setOn:on animated:YES];
            [self sendActionsForControlEvents:UIControlEventValueChanged];
        }
    }
    
    
    - (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
    {
        [super touchesCancelled:touches withEvent:event];
    
        LOG(@"touches cancelled");
    
        CGPoint location = [[touches anyObject] locationInView:self];
        if (location.x > self.frame.size.width/2) {
            [self setOn:YES animated:YES];
        }else{
            [self setOn:NO animated:YES];
        }
    
    }
    
    #pragma - trackings
    
    - (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
    {
    
        [super endTrackingWithTouch:touch withEvent:event];
    
        LOG(@"endTrackingWithTouch");
    
        m_touchedSelf = YES;
    
        if (self.value > 0.5) {
            [self setOn:YES animated:YES];
        }else{
            [self setOn:NO animated:YES];
        }
    }
    
    - (void) cancelTrackingWithEvent:(UIEvent *)event
    {
    
        LOG(@"cancelTrackingWithEvent");
    
        m_touchedSelf = YES;
    
        if (self.value > 0.5) {
            [self setOn:YES animated:YES];
        }else{
            [self setOn:NO animated:YES];
        }
    }
    

    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 UITableView or UITableViewCell cancell UITouch events of UICustomSwitch?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can switch the order this outputs the list items. I have my custom
I have two apps that use custom URL schemes to switch between each other.
I have custom UITableViewCell . It contains UITextLabel . When I press this cell
I have custom validation rule: public function customRule($check) { } Inside this rule I
I have a custom sort routine that works great, but I was curious about
I have custom UITableViewCell and UIImageView in it. I need to switch the content
For using custom DNS, I want to switch from shared mode to reserved mode
I'm using this class to make a custom switch: https://github.com/robertchin/rcswitch It subclasses UIControl. I
i have a custom tabBar class in which i switch three view controllers ,i
I have custom classes that I currently instantiate within App.xaml as resources. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.