Stepper value reset after loaded from coredate

吃可爱长大的小学妹 提交于 2019-12-12 02:57:57

问题


I am building a UITabledetail view, which contains a stepper and a UILabel.

The uilabel will show the number of stepper pressed.

My problem comes when i used core data to save the value of the uilabel. e.g. the final value of the uilabel is 30.

When i load back the data, the uilabel showed 30 but, when i press the stepper again, the uilabel reset to 1 again.

Is there any way to make the stepper continue to count based on my saved value?

Below is my code.

- (IBAction)stepperValueChanged:(id)sender 
{
    double stepperValue = ourStepper.value;
    self.label.text = [NSString stringWithFormat:@"%.f", stepperValue];


  }

回答1:


- (IBAction)stepperValueChanged:(id)sender 
{

    NSString *tempString = [NSString stringWithFormat:@"30"];// you can pass here whatever data(stepper value) that you retrieve from core data...
    double steppervalue = [tempString doubleValue];

    double stepperValue = ourStepper.value+steppervalue;
    self.label.text = [NSString stringWithFormat:@"%.f", stepperValue];


  }

Hope, this will help you..



来源:https://stackoverflow.com/questions/10395046/stepper-value-reset-after-loaded-from-coredate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!