2012-12-31 17 views
7

में सभी ऑब्जेक्ट्स के लिए एक संपत्ति बदलें, मेरे पास 0 ऑब्जेक्ट्स के साथ NSMutableArray है। उन वस्तुओं questionName, questionWhatRow, आदिएनएसएमयूटेबलएरे

जैसे मैं सभी 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 कहा जाता है, और मुझे संपत्ति, NSMutableArrayquestionsArray सभी वस्तुओं/प्रश्नों के लिए की questionCompleteOrNot@"No" को बदलने में सक्षम होना चाहता हूँ।

मेरे ScoreView रीसेट करने के लिए एक बटन है, लेकिन मैं नहीं जानता कि क्या यह में डाल करने के लिए @"No" को questionsArray की सभीquestionCompleteOrNot गुणों को बदलने के।

लंबे प्रश्न के लिए खेद है, मैं बहुत विशिष्ट होने की कोशिश कर रहा था।

संपादित करें

यहां तालिका विवरण के लिए मेरा विवरण दृश्य है।

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

तुम इतनी तरह उपयोग कर सकते हैं NSArray के makeObjectsPerformSelector:withObject:,:

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

मैं अपने ScoreView, QuestionList * QL = [[QuestionList alloc] init] में ऐसा किया; [ql.questionsArray makeObjectsPerformSelector: @selector (setQuestionCompleteOrNot :) withObject: @ "No"] ;, लेकिन यह अभी भी काम नहीं करता – jakife

+0

परिभाषित करें "काम नहीं करता"। क्या होता है? तुम क्या करने की कोशिश कर रहे हो? आपकी QuestionList क्लास आपके स्कोर व्यू क्लास से कैसे जुड़ी है? क्या गलत है यह निर्धारित करने के लिए मुझे और जानकारी चाहिए। मेरा जवाब किसी भी एनएसएमयूटेबलएरे के लिए काम करना चाहिए, इसलिए यह मुझे लगता है जैसे आपकी समस्या एक पूरी तरह से अलग सवाल है। –

+0

मेरे पास एक पूरी तरह से अलग दृश्य है, स्कोर व्यू। मेरा दूसरा विचार, प्रश्नसूची, एक एनएसएमयूटेबलएरे है। मुझे स्थानीय रूप से सरणी को समझने के लिए QuestionList प्राप्त करना पड़ा। मैं ** सभी ** प्रश्नों को पूरा करना चाहता हूं। सभी ऑब्जेक्ट्स पर कॉम्प्लेटीऑनोट गुण नहीं होने के लिए यह ऐसा प्रतीत नहीं होता है क्योंकि जब मेरा दूसरा विचार, जिसे मैं कोड पोस्ट करना भूल गया था, जो मैं एक सेकंड में करूंगा, अकसर यह संपत्ति देखने के लिए कि क्या यह कुछ नहीं है और कुछ करता है। यहां, मैं इसे प्रश्न में पोस्ट करूंगा। ** संपादित करें: बस इसे अपडेट किया गया। ** – jakife

संबंधित मुद्दे