Note that there are some explanatory texts on larger screens.

plurals
  1. POUIbutton don't change background inside IBAction
    text
    copied!<p>I have 3 custom UIButtons with text, and when user click on one of buttons I check if answer is right. If it is right I want set button background green, if not red. Then I want to show next question automatic, after a little delay (he need a bit time to see if previous answer was right). </p> <p>The problem is that UIbutton background don't change inside IBAction, but it change inside setWordAndAnswers function. And I don't have any idea why it happens(((</p> <p>Here is the code:</p> <pre><code>-(void)setWordAndAnswers{ if([[currentCollection allWards] count]&gt;0){ int randCard =arc4random_uniform([[currentCollection allWards] count]-1); currentWord=[[currentCollection allWards]objectAtIndex:randCard]; tvMainWord.text=[currentWord originalWord]; int wrightAnser =arc4random_uniform(2); for(int i=0;i[answers count];i++){ [[answers objectAtIndex:i]setBackgroundColor:[UIColor whiteColor]]; if(i==wrightAnser){ [[answers objectAtIndex:i] setTitle:[currentWord wordTranslate] forState:UIControlStateNormal]; } else{ [[answers objectAtIndex:i] setTitle:[self getRandomAnswer] forState:UIControlStateNormal]; } } } </code></pre> <p>}</p> <pre><code>- (IBAction)onClickCheckAnswer:(id)sender { if(!isGameRunning) return; UIButton *button = (UIButton *)sender; if([[sender title]isEqual:[currentWord wordTranslate]]){ [button setBackgroundColor:[UIColor greenColor]]; } else{ [button setBackgroundColor:[UIColor redColor]]; } [button setNeedsDisplay]; [NSThread sleepForTimeInterval:0.3f]; [self setWordAndAnswers]; </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload