0
我试图在同一时间加载5个图像,因为它们将它放在视图上并每5秒更改一次图像(在当前5之间更改) 我创建一个在viewDidLoad中并启动定时器当前类至极被调用时,加载所有图像的方法是这样的:从互联网同时加载各种图像objective-c
-(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;
}
但有时上推出的appcrashs,那里有没有其他解决办法abordation呢?
为什么不加载异步? – Davyd