[imageView setImageWithURL: url placeholderImage: [UIImage imageNamed:@"DefaultBanner"]];
使用此代码我正在从URL加载图像。在未从URL加载图像之前,表单不会提交。
任何人都可以帮助我修复此代码吗?
这可能是线程并发问题,如果您处理主线程中的所有内容,它将冻结,直到资产完全下载。我建议将其发送到后台线程中的串行队列,并在下载完成后将其发送到主线程。
一个例子:
-(void) GCDSerialQueuesDownload
{
NSString * anURL = @"myURL.com";
dispatch_queue_t serialQueue = dispatch_queue_create("com.dispatch.feed.serial.queue",DISPATCH_QUEUE_SERIAL);
dispatch_queue_t mainQueue = dispatch_get_main_queue();
void (^addFeedBlock)(NSString*) = ^(NSString* url) {
//your download here
dispatch_async(mainQueue,^{
//after finish you download
});
};
dispatch_async(serialQueue, ^{
addFeedBlock(anURL);
});
}