如果不使用CoreAnimation,如何避免 "CoreAnimation警告删除了未提交的CATransaction的线程"?[英] How to avoid "CoreAnimation warning deleted thread with uncommitted CATransaction" if NOT using CoreAnimation

本文是小编为大家收集整理的关于如果不使用CoreAnimation,如何避免 "CoreAnimation警告删除了未提交的CATransaction的线程"?的处理方法,想解了如果不使用CoreAnimation,如何避免 "CoreAnimation警告删除了未提交的CATransaction的线程"?的问题怎么解决?如果不使用CoreAnimation,如何避免 "CoreAnimation警告删除了未提交的CATransaction的线程"?问题的解决办法?那么可以参考本文帮助大家快速定位并解决问题。

问题描述

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

推荐答案

如 Andrew 所述,另一种确保 UI 绘制发生在主线程上的方法是使用方法 performSelectorOnMainThread:withObject:waitUntilDone: 或替代方法 performSelectorOnMainThread:withObject:waitUntilDone:modes:

- (void) someMethod
{
    […]

    // Perform all drawing/UI updates on the main thread.
    [self performSelectorOnMainThread:@selector(myCustomDrawing:)
                           withObject:myCustomData
                        waitUntilDone:YES];

    […]
}

- (void) myCustomDrawing:(id)myCustomData
{
    // Perform any drawing/UI updates here.
}

有关 dispatch_async() 和 performSelectorOnMainThread:withObjects:waitUntilDone: 之间区别的相关帖子,请参阅 主队列上的 performSelectorOnMainThread 和 dispatch_async 有什么区别?

本文地址:https://www.itbaoku.cn/post/924446.html