UIButton setTitle не изменяет заголовок немедленно

#ios #objective-c #asynchronous #uibutton

#iOS #objective-c #асинхронный #uibutton

Вопрос:

У меня возникли проблемы при написании и чтении заголовка UIButton .

Моя проблема:

 // If I execute this line of code everything works fine, the title gets changed in the UI
[self.lastButtonPressed setTitle:stringDate forState:UIControlStateNormal];

// In the next line of code I want to read the title I've set before, but everything I get is the title of the UIButton before I changed the title.
NSString *myText = [self.lastButtonPressed.titleLabel.text];
  

Возможно ли, что [UIButton setTitle] это называется асинхронным? Если да, есть ли возможность сделать этот вызов синхронным?

Ответ №1:

Вы, вероятно, currentTitle не titleLabel.text хотите. Или, возможно titleForState:UIControlStateNormal .