1
OK。我不完全清楚塊,但我經常使用它們;尤其是在執行ASIHTTPRequest時。我想傳遞一個對象到塊中,並在請求完成時爲該對象分配一個值,但我不知道如何在塊內使對象「可用」。將對象傳入ASIHTTPRequest塊
這裏是我的方法......
- (void)fetchImageAsynchronously:(NSURL *)theURL intoImageObject:(UIImage *)anImageObject
{
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:theURL];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[request setCompletionBlock:^{
NSData *responseData = [request responseData];
anImageObject = [UIImage imageWithData:responseData];
}];
[request setFailedBlock:^{
// NSError *error = [request error];
}];
[request startAsynchronous];
}
因此,請求完成時,我想anImageObject的價值是獲取圖像。但anImageObject在塊內不可用。
有人會好心幫忙嗎?