更改NSMutableArray中所有对象的属性

时间:2012-12-31 21:00:37

标签: objective-c properties nsstring nsmutablearray

我有一个NSMutableArray,有9个对象。这些对象具有许多属性,例如questionNamequestionWhatRow等。

我希望能够更改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];
}

现在,我有另一个名为ScoreViewController的课程,我希望能够将所有对象/问题的questionCompleteOrNot NSMutableArray的属性questionsArray更改为@"No"

我的ScoreView有一个重置按钮,但我不知道该怎么做才能将questionCompleteOrNot所有 questionsArray属性更改为{{1} }。

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

修改

这是我的用于tableView的DetailView。

@"No"

1 个答案:

答案 0 :(得分:10)

您可以使用NSArray的{​​{3}},如下所示:

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