iOS,ARC : Background thread freezes UI

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

我有一个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/

相关文章:

ios - 字体在 xcode 的属性检查器中不可见

iphone - Xcode:为什么我的计时器在每次滴答时计数 2 秒?

objective-c - 来自 NSSet 的 NSArray 元素未显示在 TableViewCell 中

java GUI布局建议

java - 实例化 DefaultBoundedRangeModel

java - 如何通过 GUI 使用 sleep(或类似 sleep 的东西)

ios - 无法在 MKMapview Swift 上显示注释图钉

ios - 如何避免获取关系中的子实体

swift - 如何在 Swift 中将默认 AnchorPoint 更改为 0.5、0.5

iOS - 核心数据 - 创建一个空的 NSManagedObjectContext