NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation;
for(int k=0; k<[imageArray count]; k++)
{
operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadData:) object:[imageArray objectAtIndex:k]];
[queue addOperation:operation];
[operation release];
}
使用上面的代码我调用了loadData
下载一些图像的方法。
-(void)loadData:(NSString*)newImage
{
[CATransaction begin];
[CATransaction setDisableActions:YES];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:newImage]];
NSString* appSuppPath = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* foofile = [appSuppPath stringByAppendingPathComponent:@"/PSDB"];
NSString * str =[NSString stringWithFormat:@"%@/%d.jpeg",foofile,x];
x++;
[imageData writeToFile:str atomically:YES];
[CATransaction commit];
}
图像已下载并保存。问题是小尺寸的图像被快速下载。例如,如果第 6 个图像是小尺寸图像,则它首先下载并保存为1.jpeg
. 我怎样才能按订单制作。