0

I have label in which i am loading the text value in viewDidLoad and i am changing that value on button click i want the value changed on button clicked to be remain same in the label untill we again click the label but when i move to next screen and comeback to original then again it shows the value is which is set in viewDidLoad not the changed values.

   -(void)viewDidLoad{

    testLabel.text=@"This is fine";


   }

  -(void)changeData{

    testLabel.text=@"changed data";

   }     



    -(IBAction)riskButtonAction{

   RiskViewController*targetContrlloer=[[RiskViewController alloc] init];
   [self.navigationController pushViewController:targetContrlloer animated:YES];

   }
4

3 に答える 3

2

以下のコードを試してください

 -(void)viewWillAppear:(BOOL)animated
    {
       NSString *checkFb=[[NSUserDefaults standardUserDefaults] valueForKey:@"someKey"];
       if(checkFb.lenght > 0)
       { 

        testLabel.text=checkFb;
        }

    }


   -(void)changeData{

      testLabel.text=@"changed data";
    [[NSUserDefaults standardUserDefaults] setObject: testLabel.text forKey:@"someKey"];
    [[NSUserDefaults standardUserDefaults] synchronize];


   }    

動作しているかどうか教えてください!!!

于 2013-01-04T06:19:32.630 に答える
2

Don't create new object used this code to go to the previous screen

[self.navigationController popViewControllerAnimated: YES];
于 2013-01-04T06:18:10.397 に答える
0

Just Take the Global Variable Declare it in App Delegate and assign your label value to this global variable your problem will be solve.

Still if you dont get it feel free to ask me its so simple buddy

于 2013-01-04T08:51:52.937 に答える