Mam obiekt NSMutableArray
z 9 obiektami. Obiekty te mają wiele właściwości, jak questionName
, questionWhatRow
itpZmiana właściwości wszystkich obiektów w obiekcie NSMutableArray
Chcę móc zmienić jeden z tych właściwości dla All obiektów w NSMutableArray
.
Oto moja klasa 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];
}
Teraz mam inną klasę o nazwie ScoreViewController
i chcę, aby być w stanie zmienić właściwość, questionCompleteOrNot
z NSMutableArray
questionsArray
dla wszystkich obiektów/pytania do @"No"
.
My ScoreView posiada przycisk, aby zresetować, ale nie wiem, co umieścić w nim zmienić wszystkiequestionCompleteOrNot
właściwości questionsArray
do @"No"
.
Przepraszam za długie pytanie, starałem się być bardzo konkretny.
Edytuj
Oto mój DetailView dla 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]);
zrobiłem to w moim ScoreView, QuestionList * QL = [[QuestionList alloc] startowych]; [ql.questionsArray makeObjectsPerformSelector: @selector (setQuestionCompleteOrNot :) withObject: @ "No"] ;, ale nadal nie działa – jakife
Definiuj "nie działa". Co się dzieje? Co próbujesz zrobić? W jaki sposób klasa QuestionList jest połączona z Twoją klasą ScoreView? Potrzebuję więcej informacji, aby ustalić, co jest nie tak. Moja odpowiedź powinna działać dla każdej NSMutableArray, więc brzmi dla mnie, jak twój problem jest zupełnie innym pytaniem. –
Mam zupełnie inny widok, scoreView. Mój inny widok, questionList, ma NSMutableArray. Musiałem lokalnie uzyskać QuestionList, aby objąć tablicę. Chcę ustawić ** wszystkie ** właściwości questionCompleteOrNot na wszystkich obiektach na No. Nie wydaje się, że to robię, ponieważ gdy mój drugi widok, o którym zapomniałem napisać o kodzie, co zrobię w sekundę, będzie miał tę właściwość, aby zobaczyć, czy nie ma i coś robi. Tutaj zamieszczę to w pytaniu. ** Edycja: Właśnie zaktualizowałem. ** – jakife