gpt4 book ai didi

ios - 在 View Controller 之间移动信息

转载 作者:行者123 更新时间:2023-11-28 22:03:13 27 4
gpt4 key购买 nike

我是 iOS 的新手,正在尝试弄清楚一些可能很基础的东西。我有两个 UIView,每个页面上有四个按钮,每个按钮下面有四个标签。基本上,如果我按下 View Controller 1 上的按钮 1,我希望 View Controller 2 上的所有标签都简单地显示为“2”。这是一张更好看的图片:

enter image description here

我为 View Controller 1 上的每个 UIButton 设置了 socket ,并为 View Controller 2 上的每个标签设置了 socket 。

- (IBAction)button1Pressed:(id)sender {

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"viewController2"];
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:vc animated:YES completion:NULL];

ViewController2 *vc2 = [[ViewController2 alloc]init];
vc2.label1.text = @"1";
vc2.label2.text = @"1";
vc2.label3.text = @"1";
vc2.label4.text = @"1";

}

它过渡得很好。但是,我在尝试在过渡期间更改标签文本时遇到了麻烦。我收到三个错误:“Unknown receiver: ViewController2”、“Unknown type name: ViewController2”和“Property label1 not found on object of type ViewController *”。因此,看来我在设置更改文本时遇到了问题。有谁知道我在这里做错了什么?

最佳答案

替换

vc2.label1.text = @"1";
vc2.label2.text = @"1";
vc2.label3.text = @"1";
vc2.label4.text = @"1";

vc.label1.text = @"1";
vc.label2.text = @"1";
vc.label3.text = @"1";
vc.label4.text = @"1";

并删除

ViewController2 *vc2 = [[ViewController2 alloc]init];

关于ios - 在 View Controller 之间移动信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24602084/

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