gpt4 book ai didi

ios - 覆盖 viewDidLoad 中的现有值

转载 作者:行者123 更新时间:2023-11-29 03:22:09 24 4
gpt4 key购买 nike

有没有人可以帮助我解决问题?我正在帮助一个 friend 玩游戏,但我们一直在研究如何覆盖现有整数。问题出在 xCode 中的 Objective-C。

有两个viewControllers frontPage 和secondPage。在 frontPage 中,我们将 100 分配给 viewDidLoad 方法中的 startingScore。然后我们出去到 secondPage 并从 secondPage 回来。我们想在 frontPage 中使用 secondPage 的 startingScore,但它被 viewDidLoad 覆盖了。

这是我们从 frontPage(或第一个 View Controller )得到的:

- (void)viewDidLoad
{
startingScore = 100;
mylabel1.text = [NSString stringWithFormat:@"%d", startingScore];
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"Current value of newscore is: %d",startingScore);

}

这是来自 SecondViewController 的代码:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
frontPage *destination = [segue destinationViewController];
destination.startingScore = 5000;
destination.mylabel2.text = [NSString stringWithFormat:@"%d", destination.startingScore];
NSLog(@"Current Value of destination.newscore is: %d",destination.startScore);
}

谁能帮帮我?

谢谢,

山姆 x。

最佳答案

如果您希望在首次创建 frontPage View Controller 并从那时起在别处管理时将 startingScore 设置为 100,您可以将 startingScore 的初始化移动到您的 init函数:

- (id)init
{
if(self = [super init]) {
// ...
startingScore = 100;
}
return self;
}

关于ios - 覆盖 viewDidLoad 中的现有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20936496/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com