Reputation: 18586
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
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
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
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