我在所谓的app中有2个屏幕。第一个(ViewController.m)获取值并将其发送到ViewController2.m中的方法。然后,第二个视图中标签的预加载文本将更改为传输的字符串。
案例是:
1)NSLog打印从第一页的文本字段
获取的正确输出2)但是,setText方法不会更改标签的文本。
3)奇怪的是,相同的代码可以在viewDidLoad中更改标签的文本。
- (void) setText:(NSString *)paramText {
self.myLabel.text = paramText;
NSLog(@"%@", paramText);
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.myLabel.text = @"try";
}
我如何从ViewController.m调用setText:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ikinciEkran"]) {
ViewController2 *nextController = segue.destinationViewController;
[nextController setText:self.myText.text];
}
}
答案 0 :(得分:0)
你的二传手,你需要:
_text = paramText;
答案 1 :(得分:0)
我不知道我是否理解正确。但是如果你在适合你的viewControllers之间传递字符串。例如,将VC1文本字段值转换为字符串
if([segue.identifier isEqualToString:@"ikinciEkran"]) {
NSString *textLocalString = [NSString stringWithFormat:@"%@",Viewcontroller1.text];
}
ViewController2 *nextController = segue.destinationViewController;
nextController.introString = textLocalString;
然后,在Viewcontroller2中声明Introstring
@property(weak,nonatomic) NSString *introString;
在ViewController2.m中,输入NSlog并检查
NSLOG(@"TransferString:%@",Introstring);
如果你在vewcontrller之间传输nstring值,这将有效。