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

   }
user1808433
  • 3,325
  • 4
  • 16
  • 17

3 Answers3

2

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

[self.navigationController popViewControllerAnimated: YES];
Pratik B
  • 1,599
  • 1
  • 15
  • 32
  • its ok but i have tab button so if user click third button then it will move to third screen on that screen it has also same tabs so if it will clcik on button then it will move to that other wise next so how to handle this – user1808433 Jan 04 '13 at 06:20
  • this is working but how may i place if i am moving from third to first or 4 screen to first – user1808433 Jan 04 '13 at 06:25
  • this is working but how we may get know that which tab is clicked on which screen and we have to go to that screen – user1808433 Jan 04 '13 at 06:28
2

try below code

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


   }    

let me know it is working or not!!!

Hemang
  • 1,224
  • 9
  • 15
NiravPatel
  • 3,260
  • 2
  • 21
  • 31
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

iSanjay
  • 173
  • 11