2013-04-02 44 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

相關問題