I used ASIHttprequest in my project, I know I shouldn’t change ui in a block in iOS development , as blow:
[request setCompletionBlock:^{ [self.view addSubview:view1]; }];
[request setFailedBlock:^{ [view removeFromSuperView]; }];
I know I should change ui in MainThread and may be the code above are wrong. But I have used as this for several month, if it was wrong, why it still worked? I really don’t really clear about the thread and ui in objective-c, can any one teach me?
There are two different things: blocks and threads. You can perform code in your blocks either in the background, or in the main thread. In your case you do everything correct: you perform change ui in MainThread.
You can look more about this topic –
1) about threads:
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) about blocks:
http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/00_Introduction.html