如何在A线程中调用很多方法?

时间:2012-11-08 09:31:27

标签: objective-c ios multithreading grand-central-dispatch

我有一个连接方法。我想在一个线程中使用它,因为它需要很长时间。但是这个方法触发了其他许多方法,所以我得到了如上所述的错误消息。

* _WebThreadLockFromAnyThread(bool),0x94316f0:从主线程或Web线程以外的线程获取Web锁定。不应该从辅助线程调用UIKit。*

我的代码是:

    __weak LoginViewController *weakSelf = self;
    dispatch_queue_t connectionQueue = dispatch_queue_create("connection Queue", NULL);
    dispatch_async(connectionQueue, ^{
        [weakSelf connect];
        dispatch_async(dispatch_get_main_queue(), ^{
            [spinner stopAnimating];
        });
    });

1 个答案:

答案 0 :(得分:1)

UIAlertViewUIActivityIndicator等UIKit组件不能在主线程以外的线程中使用。如果要显示警报/活动,则必须仅在主线程中显示/关闭或启动/停止。

我认为你在一个不是主线程的线程中调用[spinner stopAnimating];。如果是,那么在主线程中执行此操作。

[self performSelector:@selector(stopAnimation) onThread:[NSThread mainThread] withObject:nil waitUntilDone:NO];
相关问题