ios - Significant lag using UISlider when custom refresh is called -
a uislider embedded in tableview cell, however, significant amount of lag seems "build up" move uislider around , interact custom tableview reloading method call when uislider value changes.
whenever uislider moved around, method called updates label in uitableview (the label in same uitableviewcell uislider).
that method added uislider via:
[discoverycell.radiusslider addtarget:self action:@selector(radiussliderchanged:) forcontrolevents:uicontroleventvaluechanged];
here code update. (i didn't call reload uitableview, since want prevent tableview scrolling top upon reload).
the logic behind nsinteger "prev_value" exists prevent excessive tableview reloading.
code called when uislider moved:
cgfloat prev_value=-1; -(void)radiussliderchanged:(uislider * )sender { if (prev_value==-1) { prev_value=sender.value; return; } cgfloat currentvalue=sender.value; if (fabs(prev_value-currentvalue)>.01) { cgpoint contentoffset = self.tableview.contentoffset; //prevent tableview scrolling [self.tableview reloaddata]; [self.tableview layoutifneeded]; [self.tableview setcontentoffset:contentoffset]; prev_value=currentvalue; } }
how avoid resulting uislider lag seems "build up"? note if don't reload tableview, don't have problem, label doesn't updated.
the closest solution i've come set:
self.tableview.scrollstotop=no,
and in radius changed call:
[tableview reloaddata]
but gives 1 initial jumpy jitter ui thing.
per rmaddy's suggestion should change
[discoverycell.radiusslider addtarget:self action:@selector(radiussliderchanged:) forcontrolevents:uicontroleventvaluechanged];
to
[discoverycell.radiusslider addtarget:self action:@selector(radiussliderchanged:) forcontrolevents: uicontroleventeditingdidend];
so table reloaded after user has finished setting radius. right reloaded multiple times slider dragged around.
also ios not language it's operating system , sdk. objective-c language.
if have label in cell want update continuously can like:
[discoverycell.radiusslider addtarget:self action:@selector(updateradiuslabel:) forcontrolevents:uicontroleventvaluechanged];
then add updateradiuslabel:
method:
- (void)updateradiuslabel:(uislider *)sender { cgpoint location = [self.tableview convertpoint:sender.bounds.origin fromview:sender]; nsindexpath *indexpath = [self.tableview indexpathforrowatpoint:location]; mytableviewcellsubclass *cell = [self.tableview cellforrowatindexpath]; cell.label.text = [nsstring stringwithformate:@"%d",sender.value]; }