我在我的项目中使用了ASIHttprequest,我可以在完成块中更改ui吗?

时间:2012-12-11 11:18:32

标签: ios asihttprequest objective-c-blocks

我在我的项目中使用了ASIHttprequest,我知道我不应该在iOS开发中的块中更改ui,因为打击:

[request setCompletionBlock:^{ [self.view addSubview:view1]; }];
[request setFailedBlock:^{ [view removeFromSuperView]; }];

我知道我应该在MainThread中更改ui,可能上面的代码是错误的。但是我已经使用了几个月,如果它错了,为什么它仍然有效?我真的不清楚目标c中的线程和ui,任何人都可以教我吗?

1 个答案:

答案 0 :(得分:0)

有两种不同的东西:块和线程。您可以在后台或主线程中执行块中的代码。在你的情况下,你做的一切都是正确的:你在MainThread中执行更改ui。

您可以查看有关此主题的更多信息 -

1)关于线程: https://developer.apple.com/library/mac/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/Reference/Reference.html

2)关于块: http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/00_Introduction.html