Stepper value reset after loaded from coredate

2019-09-02 02:12发布

问题:

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..