在我的多选项卡应用程序中,一个线程关心侦听来自服务器的消息,它必须能够在收到特定消息时相机处于活动状态时关闭UIImagePickerController。该线程通过NSThread detachNewThreadSelector运行。从不同线程关闭UIImagePickerController
我设法调用通过ApplicationDelegate上线侧调用正确的顺序,但选择器没有被驳回:
- (void) closeCameraController {
[cameraTabController closeSubViewCamera]; // Invokes cancel: on the cameraSubView.
}
同一序列正常工作,当我通过映射到一个按钮的事件启动照相机覆盖的(一个 '取消' 按钮):
- (IBAction) cancel {
[[self parentViewController] dismissModalViewControllerAnimated:NO];
}
在大多数情况下,UIKit类不是线程安全的,他们只能从主线程中使用。在后台执行的长时间运行的任务通常会调用[performSelectorOnMainThread:withObject:waitUntilDone:](http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html #// apple_ref/occ/instm/NSObject/performSelectorOnMainThread:withObject:waitUntilDone :)更新UI。 – albertamg