我有2个按钮。如果按下第一个按钮,我想在下一个viewController
中通过index = 1
,如果按下第二个按钮,我想通过index = 2
。我该怎么做?如何在其他控制器中传递按钮整数? Objective-C
代码不起作用
FirstController.h
@property (nonatomic, assign) NSInteger index;
FirstController.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{ nextViewController *dvc=[segue destinationViewController];
dvc.index= _index;
}
next.h
@property (nonatomic, assign) NSInteger index;
next.m
if (self.index == 2){
_data1 = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"1.png"],nil];
}
Terminating app due to uncaught exception ‘NSInvalidArgumentException', reason: '-[RootViewController setIndex:]: unrecognized selector sent to instance 0x7faff1f18c30'
你提的问题是过于宽泛。索引是在当前的VC还是下一个VC中声明的?你是如何申报的?你是如何申报指数的? –
也可以显示您的按钮IBaction。以及您试图发送此索引值的内容。 –