Я столкнулся с небольшой проблемой (не удивительно, потому что я только начал с xcode). Я пытался решить эту проблему с государственными чиновниками, но они явно ошиблись.
Вот что я пытаюсь сделать: в первом ViewController у меня есть, например, 4 кнопки. Если пользователь нажимает первую кнопку, он попадает в ViewController2, и на ярлыке написано «Вы нажали первую кнопку». Если пользователь нажимает вторую кнопку, он попадает в ViewController2, и на ярлыке написано «Вы нажали вторую кнопку» и так далее.
Я пытался решить эту проблему с помощью операторов тегов, например:
FirstViewController.m
- (IBAction)switch:(id)sender;
{
UIButton *buttonPressed = (UIButton *)sender;
SecondViewController *second =[[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
second.buttonTag = buttonPressed.tag;
[self.navigationController pushViewController:second animated:YES];
(button.tag = 9001);
- (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;
[self.navigationController pushViewController:third animated:YES];
(button2.tag = 9002);
А вот что я сделал в 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?"];
Он всегда дает мне ярлыки от ButtonTag 9001 - Кто-нибудь знает, почему?