I have code that, when I press a button, causes the label to change. I'd tried to write code so that the label doesn't get the same value twice in a row, but it didn't work because I still get the same value in the twice in a row sometimes.
What is the right solution?
This is the code:
- (IBAction)buttonPressed:(id)sender {
if (sender == self.button) {
// Change the randomLabel by right answer
NSString *path = [[NSBundle mainBundle] pathForResource:@"words" ofType:@"plist"];
words = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSString *generateRandomLabel = [NSString stringWithFormat:@"%@", [words objectAtIndex:arc4random_uniform([words count] - 1)]];
if ([randomLabel.text isEqualToString:generateRandomLabel]) {
while ([randomLabel.text isEqualToString:generateRandomLabel]) {
generateRandomLabel = [NSString stringWithFormat:@"%@", [words objectAtIndex:arc4random_uniform([words count] - 1)]];
}
} else if (![randomLabel.text isEqualToString:generateRandomLabel]) {
[self.randomLabel setText:generateRandomLabel];
[randomLabel.text isEqualToString:generateRandomLabel];
}
}