I am making a game that assigns a label a question from a regular C array.
- (void)viewDidLoad
{
[super viewDidLoad];
for (int i = 0; i < 45; i++) {
basketball_numbers1[i] = (arc4random()%999)+100;
basketball_numbers2[i] = (arc4random()%999)+100;
for (int j = 0; j < 30; j++) {
int first = basketball_numbers1[i];
int second = basketball_numbers2[i];
basketball_questions[j] = [[NSString stringWithFormat: @"%d + %d", first, second] retain];
basketball_answers[j] = [[NSString stringWithFormat: @"%d", basketball_numbers1[i] + basketball_numbers2[i]] retain];
}
}
This code works and printed the questions and answers to the console no problem before I commented them out.
But when I'm running the emulator and type in the correct answer, the same questions stays on the label, even though the count (variable used to increase the index of the array) increases, which I confirmed via NSLog.
Some other notes: when I had manually put in values for the array, it worked no problem. Also I added in the 'retain' to the end of the array after doing some research, which actually eliminated some problems I was having before this, but I'm not sure if retain/release are used in regular C arrays or just NSArray.
Here is the code that reads in the textfield upon a button click.
- (IBAction)basketball_click:(id)sender {
basketball_input = self.basketball_textfield.text;
NSLog(@"INPUT: %@", self.basketball_textfield.text);
if ([self.basketball_textfield.text isEqualToString:(basketball_answers[count])]) {
NSLog(@"THEY ARE EQUAL");
isCorrect = TRUE;
self.basketball_textfield.text = @"";
}
...
if(isCorrect) {
NSLog(@"Retain Count: %d", [basketball_questions[count] retainCount]);
correct.text = @"CORRECT!";
basketball_right++;
count++;
NSLog(@"COUNT: %d", count);
question_label.text = basketball_questions[count];
NSLog(@"NEW QUESTION: %@", basketball_questions[count]);
}