Reputation: 25
I've been writing a simple fahrenheit/celcius converter style app. It works fine in the simulator but when I test the app on my iPhone 4, it is very jerky and slow to update as I move the slider back and forth.
My main view controller looks like this (removed some junk):
#import "MLViewController.h"
#import "MLGradeModel.h"
#import "MLGrade.h"
@interface MLViewController ()
@property (nonatomic, strong) MLGradeModel *gradeModel;
@end
@implementation MLViewController
@synthesize displayLeft = _displayLeft;
@synthesize displayRight = _displayRight;
@synthesize gradeModel = _gradeModel;
@synthesize buttonLeft = _buttonLeft;
@synthesize buttonRight = _buttonRight;
- (IBAction)dragEnter:(UISlider*)sender {
[self sliderUpdate: sender];
}
- (IBAction)sliderInput:(UISlider*)sender {
[self sliderUpdate:sender];
}
- (IBAction) sliderValueChanged:(UISlider *)sender {
[self sliderUpdate:sender];
}
-(IBAction)sliderUpdate:(UISlider*)sender
{
UILabel *myDisplayLeft = self.displayLeft;
UILabel *myDisplayRight = self.displayRight;
float sliderValue = [sender value];
int pos = sliderValue*1000/CONVERSION_SCALE;
NSString *strLeft = [self.gradeModel readGradeFromLeftAtPos:pos];
NSString *strRight = [self.gradeModel readGradeFromRightAtPos:pos];
[myDisplayLeft setText:strLeft];
[myDisplayRight setText:strRight];
// try to redraw, maybe less jerky?
[self.view setNeedsDisplay];
}
-(int) getSliderValue
{
float initialValue = [self.sliderInput value];
return initialValue * 100;
}
- (void)viewDidLoad
{
[super viewDidLoad];
MLGradeModel *model = [MLGradeModel sharedMLGradeModel];
self.GradeModel = model;
}
@end
gradeModel
is an NSMutableArray
of NSMutableArrays
, who contain NSString
values. As the slider is dragged, the corresponding position in the arrays should be read. Whose values should then be set to the UILabels.
I thought it should be the most simple thing. Outlets and actions for the UISlider have been dragged in the storyboard.
Edit: Also, when I run the app on the phone, the logs show that the slider input is taken, but the window is not updated at speed "so to say". For example, then I move the slider form left to right the event shows up in the log but the labels are redrawn with 0.5 s delay.
Edit: [self.view setNeedsDisplay];
was added as a test to force a redraw. The program works equally bad/slow when that line is commented away.
Edit: It works equally bad when I change sliderUpdate to:
-(IBAction)sliderUpdate:(UISlider*)sender
{
float sliderValue = [sender value];
int pos = sliderValue*10;
NSString *strFromInt = [NSString stringWithFormat:@"%d",pos];
[self.displayLeft setText:strFromInt];
[self.displayRight setText:strFromInt];
}
-Have I not hooked up all events from the UISlider? I have only set valueChanged to to my viewController's sliderInput (which calls sliderUpdate).
Upvotes: 1
Views: 1398
Reputation: 1187
I have this same delay issue with UISlider on an iPhone 4 with my app now i have started targeting iOS 7
On iOS 6 my sliders worked perfectly on an iPhone 4.
The same app works smoothly on a 4s and an ipad mini that i have here
EDIT
What I've just discovered is that in my app there was big difference in the UISlider performance on iPhone 4 under iOS 7 when I built for debug and built for release.
I had a bunch of logging going on in the slider - using DLog instead of NSLog - DLog is a macro that expands to an NSlog on running in debug mode and a no-op in release mode. so it appears that the logging was causing the lagging.
Check to see if you have logging going on in there and either comment them out or, if you are using Dlog, try changing the scheme to release and see if this solves your issue and see if that makes a difference,
To change to release look in Xcode menu Product-Scheme-Edit Scheme)
Made the world of difference to me.
Bit of a relief that !
Upvotes: 1