更改NSMutableArray中所有对象的属性

jak*_*ife 7 properties objective-c nsstring nsmutablearray

我有NSMutableArray9个对象.这些对象有很多属性,如questionName,questionWhatRow等.

我希望能够为其中的所有对象更改其中一个属性NSMutableArray.

这是我的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];
}
Run Code Online (Sandbox Code Playgroud)

现在,我有叫另一个类ScoreViewController的,我希望能够更改属性,questionCompleteOrNotNSMutableArray questionsArray所有对象/问题@"No".

我ScoreView有一个按钮复位,但我不知道该怎么把它改变所有 questionCompleteOrNot的属性questionsArray@"No".

很抱歉这个问题很长,我试图非常具体.

编辑

这是我的DetailView for tableView.

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]);
Run Code Online (Sandbox Code Playgroud)

Ale*_*ing 10

你可以使用NSArray's makeObjectsPerformSelector:withObject:,如下:

[questionsArray makeObjectsPerformSelector:@selector(setQuestionCompleteOrNot:) withObject:@"No"];
Run Code Online (Sandbox Code Playgroud)