如何避免“CoreAnimation警告已删除的线程与未提交的CATransaction”如果不使用CoreAnimation [英] How to avoid "CoreAnimation warning deleted thread with uncommitted CATransaction" if NOT using CoreAnimation
问题描述
就在appdelegates,applicationDidBecomeActive。我创建并启动一个线程,该线程等待异步下载然后保存数据:
Just in the appdelegates, applicationDidBecomeActive. I create and start a thread, this thread waits an asynchronous download and then save data:
- (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
}
在Organizer控制台中,完成后,我收到此警告:
In the Organizer console, when finished, I am getting this warning:
CoreAnimation: warning, deleted thread with uncommitted CATransaction;
推荐答案
另一种确保主要UI绘制的方法正如Andrew所描述的那样,线程正在使用方法 performSelectorOnMainThread:withObject:waitUntilDone:
或者 performSelectorOnMainThread:withObject:waitUntilDone:modes:
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.
}
关于 dispatch_async之间差异的相关帖子( )
和 performSelectorOnMainThread:withObjects:waitUntilDone:
参见主队列上的performSelectorOnMainThread和dispatch_async之间的区别是什么?
这篇关于如何避免“CoreAnimation警告已删除的线程与未提交的CATransaction”如果不使用CoreAnimation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!