次のコードを使用して、サーバーから写真をダウンロードしています。
-(void)viewDidLoad
{
for (int i = 0 ; i < picsNames.count ; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame: CGRectMake(i * 320.0, 0.0, 320.0, self.view.frame.size.height)];
imageView.backgroundColor = [UIColor blackColor];
imageView.tag = IMAGE_VIEWS_TAG + i;
[scrollView addSubview:imageView];
//getting the image
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(getImage:) object:imageView];
[queue addOperation:operation];
}
}
-(void)getImage:(UIImageView *)imageView
{
//getting the "image" from the server .....
[self performSelectorOnMainThread:@selector(loadPic:) withObject:[NSArray arrayWithObjects:imageView, image,nil] waitUntilDone:YES];
}
-(void)loadPic:(NSArray *)imageAndImageViewArray
{
//loading the image to imageview
UIImageView *imageView = (UIImageView *)[imageAndImageViewArray objectAtIndex:0];
imageView.image = (UIImage *)[imageAndImageViewArray objectAtIndex:1];
}
いくつかの写真を読み込んだ後、次の行でメモリの警告が表示され、アプリがクラッシュします。
[self performSelectorOnMainThread:@selector(loadPic:) withObject:[NSArray arrayWithObjects:imageView, image,nil] waitUntilDone:YES];
この問題を解決する方法がわかりません。みんな、ありがとう :)