ios - UIButton 标题标签延迟

标签 ios objective-c uibutton

我在为按钮设置标题标签时遇到问题。基本上我有 2 个屏幕,它们都有这个按钮,但它们上面写着不同的“数字”。发生的事情是在按钮标题准确反射(reflect)我所在的屏幕之前有 1-2 秒的非常明显的延迟。我尝试放置 [self.button reloadInputViews]; 但它仍然没有重新加载它,我仍然有延迟。

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

有人知道我如何强制按钮刷新它的标题标签吗?感谢您的帮助!

编辑:上下文的更多代码

        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];'

我的函数{
NSDictionary* dict = [notification userInfo];

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

已修复:在不同的线程上运行 myFunction。刚刚在主线程中做了 setTitle dispatch_sync(dispatch_get_main_queue(), ^{

最佳答案

如果您要等到从服务器检索数据后才设置标签,这似乎是您延迟的原因。注释掉您的网络代码,看看您的标签是否会立即更新。

关于ios - UIButton 标题标签延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17795732/

相关文章:

ios - func return does notReturn String from my conform to protocol StringLiteralConvertible 错误

IOS - 触摸 UIPickerView 时关闭键盘

ios - RESTful UIButton 操作的用户体验

ios - 适用于 iOS 的 Robbiehanson xmpp 框架不接收聊天消息

objective-c - 从 Controller 返回到前一个

ios - 当我在 Xcode 中运行应用程序时,按钮字体与 Storyboard字体不匹配

ios - VoiceOver 将 UITableViewCell 中的 UIButton 读取为 "dimmed"

ios - 如何在 CNContact 中快速查看联系人来源?

objective-c - 我可以使用自动释放来修复此内存泄漏吗?

iphone - 如何防止 iPhone NSNumberFormatter 舍入?