我正在尝试同时加载5张图片,因为他们将它放在视图上并每隔5秒更换一次图像(在当前的5之间切换) 我创建当前一个类,当viewdidload和启动计时器时调用,加载所有图像的方法是这样的:
-(NSMutableArray *)getAllPhotos
{
NSMutableArray * photosArray = [[NSMutableArray alloc]init];
NSString * pic0 = [NSString stringWithFormat:@"http://74.53.32.202/~ltashiro/public/Servidor/Images/0.png"];
NSString * pic1 = [NSString stringWithFormat:@"http://74.53.32.202/~ltashiro/public/Servidor/Images/1.png"];
NSString * pic2 = [NSString stringWithFormat:@"http://74.53.32.202/~ltashiro/public/Servidor/Images/2.png"];
NSString * pic3 = [NSString stringWithFormat:@"http://74.53.32.202/~ltashiro/public/Servidor/Images/3.png"];
NSURL *image0 = [NSURL URLWithString:pic0];
NSURL * image1 = [NSURL URLWithString:pic1];
NSURL * image2 = [NSURL URLWithString:pic2];
NSURL * image3 = [NSURL URLWithString:pic3];
NSMutableArray * arrayURL = [[NSMutableArray alloc]init];
[arrayURL addObject:image0];
[arrayURL addObject:image1];
[arrayURL addObject:image2];
[arrayURL addObject:image3];
for (int i = 0; i<4; i++)
{
NSData * imageData = [[NSData alloc]initWithContentsOfURL:[arrayURL objectAtIndex:i]];
Photo * aPhoto = [[Photo alloc]init];
aPhoto.photoID = (i+1);
aPhoto.photo = [[UIImage alloc]initWithData:imageData];
[photosArray addObject:aPhoto];
[aPhoto release];
[imageData release];
}
return photosArray;
}
但有时会在发布时批评,还有其他解决方案吗?
答案 0 :(得分:0)
我正在搜索此处发布的问题。我在这里找到了解决方案: http://www.switchonthecode.com/tutorials/loading-images-asynchronously-on-iphone-using-nsinvocationoperation
虽然没有测试过。