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

标签 ios objective-c multithreading ios6

就在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/

相关文章:

iphone - 使用 Grand Central Dispatch,我如何检查是否有 block 已经在运行?

c# 我是否正确处理多个线程

java - 不可变对象(immutable对象)如何帮助防止竞争条件

c - 从单独的线程调用时 pselect 不返回信号,但在单线程程序中工作正常

ios - 新的 React-Native 项目 : Build fails (ios)

ios - 如何使用 SOCIAL KIT 框架从我的 iOS 应用程序将视频上​​传到 Facebook?

ios - 单张 Flickr 照片导致荒谬的容量异常

ios - UITableViewCell subview 不遵守自动布局约束

iOS - 应用程序在 Release模式下崩溃,但在 Debug模式下不会。 [__NFCString 计数] : unrecognized selector sent to instance xxx

ios - 如果标题文本为空或未分配,如何隐藏 uibutton?