在dispatch_async块中访问IBOutlet

时间:2013-08-12 22:13:05

标签: ios objective-c scope block

如果我在调度块中调用它,它不会隐藏标签:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //Here your non-main thread.
        [self.loading setHidden:NO];


        dispatch_async(dispatch_get_main_queue(), ^{
            //Here you returns to main thread.
            [self.loading setHidden:NO];
        });
    });

这有效,但仍未隐藏:

 [self.loading setHidden:NO];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //Here your non-main thread.



        dispatch_async(dispatch_get_main_queue(), ^{
            //Here you returns to main thread.
            [self.loading setHidden:NO];
        });
    });

如何在块内访问IBOutlets?

1 个答案:

答案 0 :(得分:2)

你永远不会打电话给隐藏它的setHidden:YES。另外,你对界面所做的任何事情都应该在主线程上进行。