Ярлык не меняется соответственно - PullRequest
0 голосов
/ 08 января 2012

У меня возникает следующая проблема: метки всегда меняются на метки, определенные в теге 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?"];

Ответы [ 2 ]

1 голос
/ 08 января 2012

Может быть, потому что вы забыли закрыть конечную скобку для первой if?

if (buttonTag == 9001) {
    self.label1.text = [[NSString alloc] initWithFormat:@"Radnomtext"];
    self.label2.text = [[NSString alloc] initWithFormat:@"Randomtext"];
    self.label3.text = [[NSString alloc] initWithFormat:@"Randomtext?"];
} // bracket supposed to be here

if (buttonTag == 9002) {

или, может быть, вы установили buttonTag на неправильный экземпляр?

- (IBAction)switch2:(id)sender2

{
UIButton *buttonPressed = (UIButton *)sender2;
SecondViewController *third =[[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:third animated:YES];
second.buttonTag  = buttonPressed.tag; // supposed to be third?
[self.navigationController pushViewController:third animated:YES];
(button2.tag = 9002); 
}

И чтобы быть в безопасности, вы должны установить buttonTag до presentModalViewController.

1 голос
/ 08 января 2012

Вот пример, и вы представляете представление дважды. Я вынул модал в этом примере:

   - (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];
     }

, и использование ключевого переключателя бесполезно.Это зарезервированное слово в Цели C.

...