我的 Storyboard 中有 2 个简单 View ,它们都使用相同的 ViewController。我有以下代码来切换第二个 View ...
self.labelStatus.text = @"CHECKING";
[self performSegueWithIdentifier:@"LoginSuccess" sender:sender];
*labelStatus 在第二个 View 上。
出于某种原因,标签文本没有改变。谁能告诉我这是为什么?
最佳答案
[self performSegueWithIdentifier:@"LoginSuccess" sender:sender];
//在prepareForSegue:
方法中更改标签值
- (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";
}
}
在loginViewController.h
文件中
@property(nonatomic, strong) NSString *labelString;
在loginViewController.m
文件中
- (void)viewDidLoad
{
[super viewDidLoad];
self.labelStatus.text = labelString
}
关于IOS7 在 segue 之前在不同 View 中更改标签值(同一 Controller ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21205988/