Some_random_coder
Some_random_coder

Reputation: 147

UIButton title label delay

I am having a issue with setting the title label for a button. Basically I have 2 screen and both of them have this button, but both have different "number" written on them. What's happening is that there is a very noticeable delay of 1-2 seconds before the button title accurately reflects the screen I'm on. I tried to put [self.button reloadInputViews]; but it still does not reload it and I still get the delay.

[self.button setTitle:[NSString stringWithFormat:@"%d", [stringValue integerValue]]
             forState:UIControlStateNormal];

Does someone know how I can force the button to refresh it's title label? Thanks for the help!

EDIT: More code for context

        self.guestsField = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.guestsField.frame = CGRectMake(self.guestsLabel.frame.origin.x + self.guestsLabel.frame.size.width, 100, 40, 30);
    self.guestsField.titleLabel.font = [UIFont systemFontOfSize:20];
    [self.guestsField addTarget:self action:@selector(pressGuestsField:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:self.guestsField];'

myFunction{
NSDictionary* dict = [notification userInfo];

    if ([dict count] > 0)
    {
        [self.guestsField setTitle:[NSString stringWithFormat:@"%d", [GetOrder.NumberOfGuests integerValue]] forState:UIControlStateNormal];
    }

}

Fixed it: was running myFunction on a different thread. Just did the setTitle in the main thread dispatch_sync(dispatch_get_main_queue(), ^{

Upvotes: 4

Views: 1174

Answers (1)

JonahGabriel
JonahGabriel

Reputation: 3094

If you are waiting to set the label until after you retrieve data from the server, it seems that is the reason for your delay. Comment out your networking code and see if your label gets updated instantly.

Upvotes: 1

Related Questions