iOS、ARC:后台线程冻结 UI
我有一个 UIViewController 和 UITableView 作为子视图。当单击某个单元格时,应该显示一个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];
}
}
我应该改变什么才能让它为我工作?
I have a UIViewController with a UITableView as subview. When a certain cell was clicked an UIImagePickerController should be presented. Because of the long initialization time it takes, I perfom this process in the background when the UIViewController did appear.
Now I added ARC to my project and then it didn't still work. The UI was freezed by the initial process.
Here's my code.
- (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];
}
}
What should I change to get it working for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UIKit 不是线程安全类,不应从主线程外部调用。您不应该在后台执行此 UIImagePickerController 分配/交互。
UIKit is not a thread safe class and should not be called from outside the main thread. You should not perform this UIImagePickerController allocation/interaction in the background.