gpt4 book ai didi

ios - UILabel 即使在 dispatch_async 上也不会更新

转载 作者:行者123 更新时间:2023-11-28 20:18:09 25 4
gpt4 key购买 nike

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

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

我也试过使用 performSelectorOnMainThread 无济于事。

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

附加信息:

我还有另外两个功能,它们做同样的事情,但只是使用不同的文本。其他两个函数没有 dispatch_async 但它们都可以工作。此外,两个工作函数的通知由 NSURLConnection 发送(this post 中的方法 #2)。虽然上述非工作函数的通知是通过调用 FBRequestConnection 发送的(请参阅 this post )。

为了清楚起见,我的另外两个工作函数如下:

- (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的,因为另外两个在工作。

最佳答案

如果您在设置文本和打印 self.label 的描述之后立即设置断点,是否表明文本已更改?如果是这样,它必须在此方法触发后在其他地方重置。如果 self.label 为 nil,那是你的问题

关于ios - UILabel 即使在 dispatch_async 上也不会更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17000283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com