i having little bit confused regarding way of asking question
any how mentioning query support of image here. can please me out regarding issue
step 1: have requirement like: using cllocationmanger delegate methods fetched speed value like:
- (void)startlocationupdates{ locationmanager = [[cllocationmanager alloc] init]; locationmanager.delegate = self; locationmanager.distancefilter = kcldistancefilternone; locationmanager.desiredaccuracy = kcllocationaccuracybest; locationmanager.pauseslocationupdatesautomatically = yes; if ([[[uidevice currentdevice] systemversion] floatvalue] >= 8.0) [locationmanager requestwheninuseauthorization]; [locationmanager startupdatinglocation]; } #pragma mark #pragma mark - cllocationmanagerdelegate - (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations{ float speed = locationmanager.location.speed; float speedinkmph = speed * 3.6; // convert speed kmph. nsstring *speedvalue =[nsstring stringwithformat:@"%.f kmph ",speedinkmph]; self.currentspeedlblref.text = speedvalue; self.maxspeedlblref.text = speedvalue; }
step 2: currentspeedlblref,maxspeedlblref --> these uilabels
example: driving car --> first time opened app , got current speed of car(like: 120 kmph) , need display same value in "maxspeedlblref"(120 kmph) also
after time current speed of car if 50 kmph. need display value in "maxspeedlblref" --> max value --> means 120 kmph . because getting 120 kmph value previos
after if current speed of car if 180 kmph --> need show "maxspeedlblref" valu like: 180 kmph. because latest 1 compare 120 kmph
after close app ,
if reopen app want show vale "maxspeedlblref" --> 180 kmph. because value previous saved value
here source code:click here link
you missing few simple things here!
you need store max speed comparison - you're doing here is updating label current value every time. set class-level attribute, initial value = 0, , update whenever current speed > max speed.
there few ways can store max value it's there when next open app. easiest go user defaults. there many tutorials available - try 1 http://code.tutsplus.com/tutorials/ios-sdk-working-with-nsuserdefaults--mobile-6039
ok - using project code, here's need.
update viewcontroller.h this
// viewcontroller.h #import <uikit/uikit.h> @interface viewcontroller : uiviewcontroller @property (weak, nonatomic) iboutlet uilabel *currentspeedlblref; @property (weak, nonatomic) iboutlet uilabel *maxspeedlblref; // need store max speed @property float speedmax; -(void)loaddefaults; -(void)storedefaults; @end
and in viewcontroller.m, replace viewdidload this
- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. [self loaddefaults]; [self startlocationupdates]; }
update locationmanager function this
- (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations{ float speed = locationmanager.location.speed; float speedinkmph = speed * 3.6; // convert speed kmph. nsstring *speedvalue =[nsstring stringwithformat:@"%.f kmph ",speedinkmph]; self.currentspeedlblref.text = speedvalue; if (speedinkmph > self.speedmax) { self.speedmax = speedinkmph; [self storedefaults]; } nsstring *speedmaxvalue =[nsstring stringwithformat:@"%.f kmph ",self.speedmax]; self.maxspeedlblref.text = speedmaxvalue; }
and, add load / store functions
- (void)loaddefaults { nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; self.speedmax = [defaults floatforkey:@"speedmax"]; } - (void)storedefaults { nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; [defaults setfloat:self.speedmax forkey:@"speedmax"]; [defaults synchronize]; }
Comments
Post a Comment