标签不随 Segue 改变 [英] label not changing with Segue
本文介绍了标签不随 Segue 改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 DetailViewController 上有一个标签,当我尝试编辑它时它没有改变.
I have a label on my DetailViewController and it's not changing when I try to edit it.
这是我的代码目前的样子
This is how my code currently looks like
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"MySegue"]) {
// Get destination view
DetailViewController *vc = [segue destinationViewController];
NSLog(@"Goes here");
vc.titleLabel.text = @"My new UIlabel";
}
}
推荐答案
你可以使用 NSNotification
或者更好的在你的情况下通过 NSUserDefaults
使用它:
You could use NSNotification
or better in your case use this via NSUserDefaults
:
[[NSUserDefaults standardUserDefaults] setObject:@"My Label" forKey:@"detailTitle"];
[[NSUserDefaults standardUserDefaults] synchronise];
并在您阅读的 Detail 的 viewWillAppear 中:
and in the viewWillAppear of the Detail you read it:
self.titleLabel.title = [[NSUserDefaults standardUserDefaults] objectForKey:@"detailTitle"];
这篇关于标签不随 Segue 改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文