我有一个UIViewController,其中有一个UITableView作为 subview 。当单击某个单元格时,应该显示一个UIImagePickerController。由于初始化时间较长,因此当 UIViewController 出现时,我在后台执行此过程。
现在我将 ARC 添加到我的项目中,然后它仍然无法工作。 UI 在初始过程中被卡住。
这是我的代码。
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelectorInBackground:@selector(initImagePickerControllerInBackground) withObject:nil];
}
...
- (void)initImagePickerController
{
if (imagePickerController != nil)
return;
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.allowsEditing = YES;
imagePickerController.delegate = self;
imagePickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
}
- (void)initImagePickerControllerInBackground
{
@autoreleasepool
{
[self initImagePickerController];
}
}
我应该改变什么才能让它为我工作?
最佳答案
UIKit 不是线程安全类,不应从主线程外部调用。您不应该在后台执行此 UIImagePickerController 分配/交互。
关于iOS,ARC : Background thread freezes UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8037761/