2013-04-02 49 views
0

我有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;} 

//这里正在发送哪些问题是回答不正确,即当前问题

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

} 
} 

这家B信息上面的区域是我遇到问题的地方

当水平被清除Ç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' 

我所知道的问题是,发现很难SEGUE区分,并试图发送有关时,所有我想要的当前问题C数据要做的是显示C,当A完成时显示所有问题,没有数据正在传输,就像A正在继续B一样。B & C也是A的子类。任何帮助将不胜感激

+0

请检查您是否更改了storyboard中viewController的标识。 – Anupdas

+0

的segue标识符? – user2236306

+0

CViewController的身份 – Anupdas

回答

1

prepareForSegue方法检查赛格标识符UIStoryboardSegue.identifier它是否与您的B -VC转换匹配。

因为调用performSegueWithIdentifier:@"levelPassed"也会遇到此方法,并且您没有B -VC因此没有currentQuestion

+0

这似乎工作。唯一的问题是现在的问题在B VC中根本没有更新,这意味着当前的问题没有被更新,这里是prepareForSegue的代码。 - (void)prepareForSegue :(UIStoryboardSegue *)segue sender :(如果([segue.identifier isEqualToString:@“level1correct”]){ AddLevel1IncorrectViewController * incorrect = [segue destinationViewController]; incorrect.currentQuestion = self.currentQuestion;} }' – user2236306

+0

我没有得到主要问题:当你的'AddLevel1IncorrectViewController'中的'currentQuestion'在显示时没有设置? –

+0

在答案A中的问题被错误地回答时,B视图控制器被按下。A将当前问题的值传递给B,因此B可以显示关于所有问题的信息,取决于当前的问题值。这有道理吗? – user2236306

相关问题