Ok here goes.
I have an if statement running to check whether a number is in a Mutable Set, if yes then to regenerate the number, however this only works once and I do not want 100 different if Statements, which don't work. I have tried a do and do-while loop, which cause the app to freeze and a for loop which doesn't work.
I've been told to run a thread to run the loop but I cannot get one to work in the first place.
So two questions.
Can I run a loop in a thread in a button action?
How would I get this to work properly?
Heres my button code:
I have an if statement running to check whether a number is in a Mutable Set, if yes then to regenerate the number, however this only works once and I do not want 100 different if Statements, which don't work. I have tried a do and do-while loop, which cause the app to freeze and a for loop which doesn't work.
I've been told to run a thread to run the loop but I cannot get one to work in the first place.
So two questions.
Can I run a loop in a thread in a button action?
How would I get this to work properly?
Heres my button code:
Code:
- (IBAction)noButton {
[previousGuess addObject:[NSNumber numberWithInt:thisNumber]];
NSString *theValue = [NSString stringWithFormat:@"%d", tries];
triesLabel.text = theValue;
++tries;
NSString *theNumber = [NSString stringWithFormat:@"%d", thisNumber];
thisNumber = random() % 100 + 1;
NSNumber *lol = [NSNumber numberWithInt:thisNumber];
if([previousGuess containsObject:lol] ==YES) {
NSLog(@"Number matched: %d", [lol integerValue]);
thisNumber = random() % 100 + 1;
}
[previousGuess addObject:[NSNumber numberWithInt:thisNumber]];
isLabel.text = @"Is your number: ";
guessLabel.text = theNumber;
}