UILabel甚至不会在dispatch_async上更新 [英] UILabel won't update even on dispatch_async

查看:150
本文介绍了UILabel甚至不会在dispatch_async上更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的标签不会更新?

Any reason why my label won't update?

- (void)setLabel:(NSNotification*)notification {
    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"setLabel");
        [self.label setText:@"My Label"];
    });
}

我也尝试过使用performSelectorOnMainThread无效.

I've also tried using performSelectorOnMainThread to no avail.

请注意,setLabel出现在日志中.

Note that setLabel is appears on the log.

其他信息:

我还有另外两个功能,它们执行相同的操作,但仅使用不同的文本.另外两个函数没有dispatch_async,但是它们都可以工作.另外,这两个工作功能的通知是由NSURLConnection发送的(此帖子中的方法2).上面的有关非工作功能的通知是通过调用FBRequestConnection发送的(请参见这篇文章).

I also have two other functions which does the same thing but only with a different text. The two other functions doesn't have dispatch_async but they both work. Also, the notification of the two working function was sent by NSURLConnection (method #2 in this post). While the notification of the non working function above, was sent by a call to FBRequestConnection (see this post).

为清楚起见,我的其他两个工作功能如下:

For clarity, my two other working functions is as follows:

- (void)setLabel2:(NSNotification*)notification {
    NSLog(@"setLabel2");
    [self.label setText:@"My Label 2"];
}    
- (void)setLabel3:(NSNotification*)notification {
    NSLog(@"setLabel3");
    [self.label setText:@"My Label 3"];
}

是的,我确实尝试删除了我的代码中的dispatch_async.实际上,最初没有dispatch_async,因为其他两个都在工作.

Yes I did try to remove dispatch_async in my code. In fact, originally there was no dispatch_async because the other two were working.

推荐答案

如果在设置文本并打印self.label的描述后立即设置断点,是否表明文本已更改?如果是这样,则在触发此方法后必须将其重置为其他位置.如果self.label为零,那么您有问题

If you set a break point right after where you set the text and print description of self.label does it show the text has changed? If so it must be getting reset somewhere else after this method fires. If self.label is nil than there's your problem

这篇关于UILabel甚至不会在dispatch_async上更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆