iOS,ARC:后台线程冻结UI

时间:2011-11-07 14:24:50

标签: ios xcode user-interface uiimagepickercontroller automatic-ref-counting

我有一个带有 UITableView UIViewController 作为子视图。单击某个单元格时,应显示 UIImagePickerController 。由于需要很长的初始化时间,当 UIViewController 出现时,我在后台执行此过程。
现在我将ARC添加到我的项目中,然后它仍然无法正常工作。用户界面被初始流程冻结了。

这是我的代码。

- (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];
    }
}

为了让它适合我,我应该改变什么?

1 个答案:

答案 0 :(得分:5)

UIKit不是线程安全类,不应该从主线程外部调用。您不应该在后台执行此UIImagePickerController分配/交互。