我有3个VC。一个显示问题和答案的A.一旦水平清除,当错误地选择问题C时显示B. 我有一个问题从A-B& A-C。 这是我的代码
#import "AViewController.h"
#import "BViewController.h"
#import "CViewController.h"
@interface AViewController ()
@end
现在这里是实现代码
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
BViewController *incorrect = [segue destinationViewController];
incorrect.currentQuestion = self.currentQuestion;}
//这里A发送有关哪个问题被错误回答的B信息,即当前问题
- (void)viewDidLoad
{
[super viewDidLoad];
rootArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Addition1" ofType:@"plist"]];
currentQuestion = -1;
[self showNextQuestion];
}
-(void) showNextQuestion{
currentQuestion++;
if (currentQuestion <= 3) {
int numItems = [rootArray count];
NSMutableArray *question = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *A = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *B = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *C = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *addimage = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *Answer = [NSMutableArray arrayWithCapacity:numItems];
for (NSDictionary *itemData in rootArray) {
[question addObject:[itemData objectForKey:@"question"]];
[A addObject:[itemData objectForKey:@"A"]];
[B addObject:[itemData objectForKey:@"B"]];
[C addObject:[itemData objectForKey:@"C"]];
[addimage addObject:[itemData objectForKey:@"ImageUse"]];
[Answer addObject:[itemData objectForKey:@"ANS"]];
}
self.questionasked.text = question[currentQuestion];
self.answer1.text = A[currentQuestion];
self.answer2.text = B[currentQuestion];
self.answer3.text = C[currentQuestion];
additionImage.image = [UIImage imageNamed:addimage[currentQuestion]];
self.correctAns = Answer[currentQuestion];}
else{
NSLog(@"End of Array ");
[self performSegueWithIdentifier:@"levelpassed" sender:nil];
}
}
上面这个区域是我遇到问题的地方
当电平被清除时,C VC显示
错误[CViewController setCurrentQuestion:]: unrecognized selector sent to instance 0x71cae70
2013-03-30 21:17:31.264 thefyp[14311:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CViewController setCurrentQuestion:]: unrecognized selector sent to instance 0x71cae70'
我知道问题是A发现难以区分segue并且正在尝试发送关于当前问题的C数据,当我想要做的就是当A完成显示所有问题并且没有数据正在显示时像A一样转向B. B&amp; C也是A的子类。任何帮助都将受到赞赏
答案 0 :(得分:1)
在prepareForSegue
方法中,检查segue标识符UIStoryboardSegue.identifier
是否与转换到B
- VC相匹配。
因为调用performSegueWithIdentifier:@"levelPassed"
也会遇到此方法,并且您没有B
- VC,因此没有currentQuestion
。