Here is the problem – I have a class, which is a subclass of UIView (a card). It creates a button on itself and it’s calling changeStateIndicator: when user touches it.
Then the card has to flip after the button is pressed and the button should change it’s color (actually, the image). But it’s not happening at all, so the flip starts before button has changed. Here is my code:
//Adding a button to my view
UIButton *changeStateButton = [UIButton buttonWithType:UIButtonTypeCustom];
[changeStateButton setImage:[UIImage imageNamed:imageToInitWith] forState:UIControlStateNormal];
[changeStateButton setImage:[UIImage imageNamed:imageToInitWith] forState:UIControlStateHighlighted];
changeStateButton.frame = CGRectMake(0, 0, 30, 30);
changeStateButton.center = CGPointMake(self.bounds.size.width/2+([myWord length]*8)+17, 35);
changeStateButton.tag = 77;
[changeStateButton addTarget:self action:@selector(changeStateIndicator:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:changeStateButton];
//Method which is called when the button is touched
- (void)changeStateIndicator:(UIButton *)sender
{
[sender setImage:[UIImage imageNamed:@"StateYellow"] forState:UIControlStateNormal];
[sender setImage:[UIImage imageNamed:@"StateYellow"] forState:UIControlStateHighlighted];
currentWord.done = [NSNumber numberWithInt:currentWord.done.intValue-10];
[self prepareForTest];
}
//Method which flips the card
- (void)prepareForTest
{
testSide = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cal_small3"]];
[UIView transitionFromView:self toView:testSide duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:nil];
}
My guess is that the sender doesn’t change it’s image until the method -changeStateIndicator comes to it’s end, but I’m not pretty sure this is the actual problem. Help me please.
try just deferring this call:
If that sort of works but its still not how you want it, then use dispatch_after() or
(You can use the second call with a time of “0” instead of the dispatch if you want – same thing.)