iOS UISlider values mismatched
Asked Answered
T

3

6

I have implemented Vertical Slider in one of my App which extends UISlider. when scrolling is ended/done I am sending commands to the server with the Slider values. Sometimes when I scroll fast up/down and release then slider values are getting mismatched before sending command and after sending command.

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   NSLog(@"Value of Slider before sending command=%f",self.value);
   [self sendCommand]; // Here value is something else  
   [super touchesEnded:touches withEvent:event];
   NSLog(@"Slider value after sending command=%f",self.value); // Here value changed
}

But if I place super call before sending command then everything works fine. Please explain if anyone knows why this is happening.

[super touchesEnded:touches withEvent:event];

More interesting fact is if I don't call super then also everything works well.

Tola answered 24/3, 2017 at 18:7 Comment(4)
Below link may be useful to you https://mcmap.net/q/506351/-iphone-programming-uislider-to-position-at-clicked-locationXena
@RajeshDharani I checked link but that seems to be not related what I am looking for. Anyways Thankyou.Tola
I explained it below . Please check it out.Haymo
@Haymo Please check my reply, I appreciate your answer but unfortunately thats not a case.Tola
S
0

This is because the method [super touchesEnded:touches withEvent:event]; is where the slider updates it's value, based on the interaction. So the value is out of date before super is called.

A call to super should usually be the first line of an overridden method.

Snakeroot answered 24/3, 2017 at 18:16 Comment(1)
Thank you for your response, I just like to confirm why those values are not getting out dated everytime. Even I try synchronize block to make sure another next event don't update values, but that also didn't worked. So I place timer and then call super after some delay will those values will outdated everytime?Tola
S
0

Even though the name touchesEnded: implies that the slider is done updating, it still might update the value depending on how the user lifted up their finger. This makes sense if you think about a user sliding quickly and then lifting up their finger—they probably expect it to go slightly farther in that direction than their finger actually went.

Suburb answered 24/3, 2017 at 23:49 Comment(1)
Thank you for explaining, from logs it looking same which you are explaining. Because values are being updated. I am looking of some doc. link or more explanation with which I can reproduce it everytime.Tola
H
-1

UIKit calls this method when a finger or Apple Pencil is no longer touching the screen. Many UIKit classes override this method and use it to clean up state involved in the handling of the corresponding touch events. The default implementation of this method forwards the message up the responder chain. When creating your own subclasses, call super to forward any events that you do not handle yourself. For example, [super touchesEnded:touches withEvent:event];

If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, even if your implementations do nothing.

Haymo answered 1/4, 2017 at 15:38 Comment(1)
Than you for your response, yes I read this on apple site. If you will check my question according to it everything is working fine if I remove super call. So that must not be the reason.Tola

© 2022 - 2024 — McMap. All rights reserved.