0

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];


  }
Clarence
  • 1,951
  • 2
  • 34
  • 49

1 Answers1

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

Nitin
  • 7,455
  • 2
  • 32
  • 51
  • Many thanks, but what if the string is a variable? every time the value changes? – Clarence May 01 '12 at 09:21
  • `NSString *tempString = [NSString stringWithFormat:@"%d",yourvariablevalue];`...hope that will help you – Nitin May 01 '12 at 09:29
  • NSString *tempString = [NSString stringWithFormat:@"%.d", label.text], like this? – Clarence May 01 '12 at 10:17
  • Yes, you can anyway according to your requirements..I just past that code according to your function.. – Nitin May 01 '12 at 10:21
  • In my case the number is totally incorrect it become some nonsense numbers like 2130123929. Do you know why this happens? – Clarence May 01 '12 at 10:26
  • the stepper should i set value change or touch down or others? Thanks – Clarence May 01 '12 at 10:28
  • It's garbage value for any variable..when you declare any variable initially assign 0 to that float or int variable – Nitin May 01 '12 at 10:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/10735/discussion-between-clarence-and-nit) – Clarence May 01 '12 at 10:30