2012-12-31 4 views
7

私はNSMutableArrayに9個のオブジェクトがあります。これらのオブジェクトは、などquestionNamequestionWhatRowNSMutableArray内のすべてのオブジェクトのプロパティを変更する

のように私はNSMutableArray内のオブジェクトのすべてのためにこれらのプロパティの1つを変更することができるようにしたい、多くの特性を有しています。

ここにNSMutableArrayクラスがあります。

-(id) init 
{ 
    self = [super init]; 

    if (self) 
    { 
     self.questionsArray = [[NSMutableArray alloc] init]; 

     Question *newQuestion = [[Question alloc] init]; 
     newQuestion.questionName = @"What is the name of the girl who has to fetch water for her family every day?"; 
     newQuestion.questionRowName = @"Question 1"; 
     newQuestion.questionAnswer = @"Nya"; 
     newQuestion.questionHint = @"Maybe if you read the book you would know"; 
     newQuestion.questionWhatRow = @"Nya"; 
     newQuestion.questionCompleteOrNot = @"No"; 
     newQuestion.pointForQuestion = 1; 
     [self.questionsArray addObject:newQuestion]; 

     newQuestion = [[Question alloc] init]; 
     newQuestion.questionName = @"What is Nya's sister's name?"; 
     newQuestion.questionRowName = @"Question 2"; 
     newQuestion.questionAnswer = @"Akeer"; 
     newQuestion.questionHint = @"Maybe if you read the book you would know"; 
     newQuestion.questionWhatRow = @"Nya"; 
     newQuestion.questionCompleteOrNot = @"No"; 
     newQuestion.pointForQuestion = 1; 
     [self.questionsArray addObject:newQuestion]; 

     newQuestion = [[Question alloc] init]; 
     newQuestion.questionName = @"What people is Nya's mother scared of when her father and sons go hunting?"; 
     newQuestion.questionRowName = @"Question 3"; 
     newQuestion.questionAnswer = @"Dinka"; 
     newQuestion.questionHint = @"Maybe if you read the book you would know"; 
     newQuestion.questionWhatRow = @"Nya"; 
     newQuestion.questionCompleteOrNot = @"No"; 
     newQuestion.pointForQuestion = 1; 
     [self.questionsArray addObject:newQuestion]; 

     newQuestion = [[Question alloc] init]; 
     newQuestion.questionName = @"What is Salva scared of when he is in the Akobo desert?"; 
     newQuestion.questionRowName = @"Question 4"; 
     newQuestion.questionAnswer = @"Lions"; 
     newQuestion.questionHint = @"He is scared of an animal because it ate his friend Marial"; 


     newQuestion = nil; 

    } 

    return self; 
} 

-(NSUInteger)count 
{ 
    return questionsArray.count; 
} 


- (Question *)questionAtIndex:(NSUInteger)index 
{ 
    return [questionsArray objectAtIndex:index]; 
} 

は今、私はScoreViewControllerと呼ばれる別のクラスを持っている、と私は@"No"に、すべてのオブジェクト/質問のためNSMutableArrayquestionsArrayquestionCompleteOrNotをプロパティを変更できるようにしたいです。

私ScoreViewは、リセットするボタンがありますが、私は@"No"questionsArrayすべてquestionCompleteOrNotのプロパティを変更するには、それに入れているかわかりません。

長い質問のため申し訳ありませんが、私は非常に具体的にしようとしていました。

編集

ここは、tableViewのDetailViewです。

if ([[selectedQuestion questionCompleteOrNot] isEqualToString:@"No"]) 
    { 
     if ([[selectedQuestion questionAnswer] caseInsensitiveCompare:answerField.text] == NSOrderedSame) 
     { 
      // Show the correct label 
      [correctLabel setHidden:NO]; 
      correctLabel.text = @"Correct!"; 
      correctLabel.textColor = [UIColor greenColor]; 

     } 
     else 
     { 
      // Show the incorrect label 
      [correctLabel setHidden:NO]; 
      correctLabel.text = @"Incorrect"; 
      correctLabel.textColor = [UIColor redColor]; 
      [incorrectPlayer play]; 
      [[selectedQuestion questionCompleteOrNot] isEqualToString:@"Yes"]; 

     } 

     // Erase the text in the answerField 
     answerField.text = @""; 
    } 
    if ([[selectedQuestion questionCompleteOrNot] isEqualToString:@"Yes"]) 
    { 
     UIAlertView *error = [[UIAlertView alloc] 
           initWithTitle:@"Error" 
           message:@"You already answered this question. Please click the reset button on the score view to restart." 
           delegate:self 
           cancelButtonTitle:@"Okay!" 
           otherButtonTitles:nil]; 

     [error show]; 
     answerField.text = @""; 
    } 

    selectedQuestion.questionCompleteOrNot = @"Yes"; 
    correctLabel.text = @""; 
    NSLog(@"Selected question's questionCompleteOrNot is %@", [selectedQuestion questionCompleteOrNot]); 

答えて

10

あなたはそうのように、NSArraymakeObjectsPerformSelector:withObject:を使用することができます。私は私のScoreViewでこれをやった

[questionsArray makeObjectsPerformSelector:@selector(setQuestionCompleteOrNot:) withObject:@"No"]; 
+0

、QuestionList * QL = [[QuestionListのalloc]のinit]; [ql.questionsArray makeObjectsPerformSelector:@selector(setQuestionCompleteOrNot :) withObject:@ "No"];しかし、それでも動作しません。 – jakife

+0

「動作しません」と定義します。何が起こるのですか?あなたは何をしようとしているのですか? QuestionListクラスはScoreViewクラスにどのように接続されていますか?私は何が間違っているかを判断するためにさらに情報が必要です。私の答えはどのNSMutableArrayでも動作するはずですので、あなたの問題はまったく別の質問ですね。 –

+0

私は、scoreViewと全く違った見方をしています。他のビュー、questionListにはNSMutableArrayがあります。私は局所的にQuestionListを取得して配列を取得しなければならなかった。私はすべてのオブジェクトのquestionCompleteOrNotプロパティを**に設定したいと思います。それはやっているようには見えません。私がコードを投稿するのを忘れた私の他のビューそのプロパティは、それがノーであるかどうかを確認し、何かをします。ここでは、質問に投稿します。 **編集:ちょうどそれを更新** ** – jakife

関連する問題