gpt4 book ai didi

ios - 标签不会相应改变

转载 作者:行者123 更新时间:2023-11-28 23:08:42 25 4
gpt4 key购买 nike

我遇到了以下问题:标签总是更改为标签 9001 中定义的标签。有人可以帮我发现我的错误吗?

ViewController.m:

- (IBAction)switch0:(id)sender

{(button.tag = 9001);
UIButton *buttonPressed = (UIButton *)sender;
SecondViewController *second =[[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
second.buttonTag = buttonPressed.tag;
}


- (IBAction)switch2:(id)sender2

{ (button2.tag = 9002);
UIButton *buttonPressed = (UIButton *)sender2;
SecondViewController *third =[[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:third animated:YES];
second.buttonTag = buttonPressed.tag;

SecondViewcontroller.m

  - (void)viewDidLoad
{
[super viewDidLoad];

if (buttonTag == 9001) {
self.label1.text = [[NSString alloc] initWithFormat:@"Radnomtext"];
self.label2.text = [[NSString alloc] initWithFormat:@"Randomtext"];
self.label3.text = [[NSString alloc] initWithFormat:@"Randomtext?"];
}
if (buttonTag == 9002) {
self.label1.text = [[NSString alloc] initWithFormat:@"Radnomtext2"];
self.label2.text = [[NSString alloc] initWithFormat:@"Randomtext2"];
self.label3.text = [[NSString alloc] initWithFormat:@"Randomtext2?"];

最佳答案

这是一个例子,你展示了两次 View ,我在这个例子中去掉了模式:

   - (IBAction)switch0:(id)sender

{
UIButton *buttonPressed = (UIButton *)sender;
SecondViewController *second =[[SecondViewController alloc] initWithNibName:nil bundle:nil];

NSInteger tagToSet = 9001;
second.buttonTag = tagToSet;;
[self.navigationController pushViewController:second animated:YES];
}

并且使用关键字 switch 是不好的。它是 Objective C 中的保留字。

关于ios - 标签不会相应改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8778781/

25 4 0