There are 2 buttons in the ViewController . In NextViewController you need to determine which of the buttons was pressed and, based on this, select which array to work with.

I tried to pass the index but it does not work

ViewController.h

 @property (nonatomic, assign) NSInteger index; 

ViewController.m

 -(IBAction)Method1:(id)sender { self.index = 1; [self performSegueWithIdentifier:@"Segue" sender:self]; } -(IBAction)Method2:(id)sender { self.index = 2; [self performSegueWithIdentifier:@"Segue" sender:self]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { ViewController *dvc=[segue destinationViewController]; dvc.index = _index; } if (self.index == 2){ _data1 = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"1.png"],[UIImage imageNamed:@"2.png"],nil] } if (self.index == 2){ _data2 = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"5.png"],[UIImage imageNamed:@"6.png"],nil] } 

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RootViewController setIndex:]: unrecognized selector sent to instance 0x7faff1f18c30'

  • but what if you change the property attribute attribute on strong? - German Polyansky

2 answers 2

The error indicates that you do not have an index variable in the RootViewController class, add it, and you will be happy. At the same time, the method itself works exactly as you expect.

  • The problem is that I use pageViewController . index I need to regulate content in ModelController Can it be easier to use nsuserdefaults ? And then something got confused where and what to transmit. - user214155
  • And the RootViewController class is what? Could you change the code so that it is clear in what class - AntiVIRUZ

In the Method1 and Method2 methods, you manually load the controller, fill it with data and manually push it into the navigationController.

1) UIViewController * vc = [[UIStoryboard storyboard WithName: @ "MainStoryboard" bundle: nil] instantiateViewControllerWithIdentifier: @ "viewForPopover"]; 2) vc.index = 1 3) [self.navigationController pushViewController: vc];

PS: may be slightly different for different IDs and hierarchies