Cocorico
Cocorico

Reputation: 2347

Thread issue where updating a label make a UIImageview invisible

I have a situation that is confusing me lots. I have a class that has 2 completely separate things: An animated UIImage and a UILabel. They have different outlets, are not connected.

When the app runs, it does this:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.monsterMachine setHidden:NO]; //monsterMachine is UIImageView
    [self.monsterMachine startAnimating];
});

but then when I do this:

    [self.futText setText:@"blah"]; // is UILabel

it causes the monsterMachine UIImageView to not animate anymore. Things I have found:

Right after I setText:@blah" I can use NSLog to watch and see that self.monsterMachine.isAnimated suddenly goes from 1 to 0, ie from YES to NO.

If self.futText is ALREADY saying "blah", then I can run setText:@"blah" on it as many times as I want and nothing happens, it is ONLY when I change it to some value other than blah that UIImageView stops animating and disappears

If I don't use main_queue to show and animate monsterMachine, it won't display at ALL, so how do I diagnose or fix this?

Upvotes: 0

Views: 44

Answers (1)

tzx7788
tzx7788

Reputation: 37

That's weird it works for me perfect. Did you call [self.futText setText:@"blah"]; in main queue also? Here is a small answer to why setting text @"blah" won't stops the animation: Strings like @"blah" are stored in stacks which have the same reference as long as they have the same context. In this case [self.futText setText:@"blah"] will do nothing because the internal implementions are like:

void setText:(NSString*) text {
  if ( _text == text ) then return;//if reference is the same then do nothing
  _text = text;
  some rendering..
}

Upvotes: 1

Related Questions