gpt4 book ai didi

ios - 如果不使用 CoreAnimation 如何避免 "CoreAnimation warning deleted thread with uncommitted CATransaction"

转载 作者:可可西里 更新时间:2023-11-01 06:20:48 27 4
gpt4 key购买 nike

就在appdelegates中,applicationDidBecomeActive。我创建并启动一个线程,这个线程等待异步下载然后保存数据:

 - (void)applicationDidBecomeActive:(UIApplication *)application
{
// begins Asynchronous download data (1 second):
[wsDataComponents updatePreparedData:NO];

NSThread* downloadThread = [[NSThread alloc]
initWithTarget:self
selector: @selector (waitingFirstConnection)
object:nil];
[downloadThread start];
}

然后

-(void)waitingFirstConnection{    

while (waitingFirstDownload) {
// Do nothing ... Waiting a asynchronous download, Observers tell me when
// finish first donwload
}

// begins Synchronous download, and save data (20 secons)
[wsDataComponents updatePreparedData:YES];

// Maybe is this the problem ?? I change a label in main view controller
[menuViewController.labelBadgeVideo setText:@"123 videos"];

// Nothig else, finish and this thread is destroyed
}

在管理器控制台中,完成后,我收到此警告:

CoreAnimation: warning, deleted thread with uncommitted CATransaction;

最佳答案

在非主线程上使用 UIKit UI API 时最常出现此错误。您不必直接使用 Core Animation 就可以看到这一点。所有 UIView 都由 Core Animation 层支持,因此无论您是否直接与之交互,Core Animation 都在使用中。

您的问题中没有足够的代码来确定确切的问题,但您正在使用多线程这一事实表明您的问题与我所描述的一样。您是否在下载完成和/或数据保存后更新您的用户界面?如果是这样,您需要将 UI 更新移回主线程/队列。如果您使用 GCD 而不是 NSThread,这会更容易:

// download is finished, save data
dispatch_async(dispatch_get_main_queue(), ^{
// Update UI here, on the main queue
});

关于ios - 如果不使用 CoreAnimation 如何避免 "CoreAnimation warning deleted thread with uncommitted CATransaction",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19544207/

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