LiamB
LiamB

Reputation: 18586

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?

Upvotes: 0

Views: 849

Answers (3)

Suhit Patil
Suhit Patil

Reputation: 12023

[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
}

Upvotes: 1

kkodev
kkodev

Reputation: 2607

You can customise your destinationViewController (properties, views, etc) in prepareForSegue: method, which is called before segue is executed:

- (void)prepareForSegue:(UISegue *)segue {
    if ([segue.identifier isEqualToString:@"mySegue"]) {
        UIViewController *destVC = segue.destinationViewController;
        // do your customisation
    }
}

Upvotes: 1

Dinesh
Dinesh

Reputation: 2204

Edit- If you need to change the label in the same view controller, then you should modify the label in the prepareForSegue method.

Upvotes: 0

Related Questions