问题描述
就在 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 有什么区别?
相关问答
核心动画警告。"未提交的CATransaction"
Coreanimation,Avfoundation和制作视频导出的能力
由于CoreAnimation和CG图像而导致的脏内存
如何使用coreanimation使圆圈像时钟倒计时一样动画
objective-c - CoreAnimation 和 CoreGraphics这两个框架的区别
使用Monotouch中的coreanimation对自定义属性进行动画?
Git拉动删除了未提交的修改
GitHub for Mac同步删除了我未提交的更改
GIT Pull删除了我的提交
如何将3D OpenGL矩阵转换转换为coreanimation catransform3ds?