LiamB LiamB - 2 months ago 4x
Objective-C Question

IOS7 Change value of label in different view before segue (Same controller)

I have 2 simple views in my Storyboard and both use the same ViewController. I have the following code to switch the the second view...

self.labelStatus.text = @"CHECKING";
[self performSegueWithIdentifier:@"LoginSuccess" sender:sender];

*labelStatus is on the second view.

For some reason the labels text is not changing. Can anyone advise why this is?

[self performSegueWithIdentifier:@"LoginSuccess" sender:sender];

//change the label value in prepareForSegue: method

- (void)prepareForSegue:(UIStoryboardSegue *)segue {
    if ([segue.identifier isEqualToString:@"LoginSuccess"]) {
        UIViewController *loginVC = segue.destinationViewController;

       //declare the string in .h file and assign it in viewDidLoad in loginVC

        loginVC.labelString = @"CHECKING";

in loginViewController.h file

@property(nonatomic, strong) NSString *labelString;

in loginViewController.m file

- (void)viewDidLoad
    [super viewDidLoad];
    self.labelStatus.text = labelString