How to avoid “CoreAnimation warning deleted thread with uncommitted CATransaction” if NOT using CoreAnimation

前端 未结 3 719
北恋
北恋 2021-01-06 14:37

Just in the appdelegates, applicationDidBecomeActive. I create and start a thread, this thread waits an asynchronous download and then save data:

 - (void)a         


        
相关标签:
3条回答
  • 2021-01-06 14:46

    Another way of ensuring any UI drawing occurs on the main thread, as described by Andrew, is using the method performSelectorOnMainThread:withObject:waitUntilDone: or alternatively 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.
    }
    

    For a related post on the difference between dispatch_async() and performSelectorOnMainThread:withObjects:waitUntilDone: see Whats the difference between performSelectorOnMainThread and dispatch_async on main queue?

    0 讨论(0)
  • 2021-01-06 14:49

    This error is most commonly seen when using UIKit UI API on a non-main thread. You don't have to be directly using Core Animation to see this. All UIViews are backed by a Core Animation layer, so Core Animation is in use whether you're interacting directly with it or not.

    There's not enough code in your question to identify the exact problem, but the fact that you're using multithreading is a clue that your problem is as I've described. Are you updating your UI after the download is complete and/or the data is saved? If so, you need to move the UI update back to the main thread/queue. This is easier if you use GCD instead of NSThread:

    // download is finished, save data
    dispatch_async(dispatch_get_main_queue(), ^{
        // Update UI here, on the main queue
    });
    
    0 讨论(0)
  • 2021-01-06 15:08

    I have found the problem: Is changing a label in menuViewController

    In this thread, i use a isntance variable than is de menuViewController:

    [menuViewController.labelBadgeVideo setText:@"123 videos"];
    

    If i comment this line no warning appears

    (Now I have to find out how to change this label without warning)

    0 讨论(0)
提交回复
热议问题