0
嗨我试图显示图像从json到CollectionView。从json显示图像(url的图像)vlaue收集查看
我的代码是...
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://zoo.com/jh/image.php"]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options: NSJSONReadingMutableContainers error: &err];
NSArray *headlines=[jsonArray1 objectForKey:@"image_gallery"];
for (int i=0;i<[headlines count]; i++)
{
NSString *moblinks=[[headlines objectAtIndex:i]objectForKey:@"image_url"];
[self.itemshowdetailsAr objectAtIndex:moblinks];
NSLog(@"%@",moblinks);
}
和我的结果在控制台
2014-06-20 15:05:27.005 Collection[3945:60b] http://xxxxxx/jh/ju_image/gal_1.jpg
2014-06-20 15:05:27.007 Collection[3945:60b] http://xxxxxx/jh/ju_image/gal_2.jpg
2014-06-20 15:05:27.007 Collection[3945:60b] http://xxxxxx/jh/ju_image/gal_3.jpg
2014-06-20 15:05:27.007 Collection[3945:60b] http://xxxxxx/jh/ju_image/gal_4.jpg
2014-06-20 15:05:27.008 Collection[3945:60b] http://xxxxxx/jh/ju_image/gal_5.jpg
2014-06-20 15:05:27.008 Collection[3945:60b] http://xxxxxx/jh/ju_image/gal_6.jpg
我的CollectionView代码
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
NSString *ImageURL =[self.itemshowdetailsAr objectAtIndex:indexPath.row];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
cell.imageView.image = [UIImage imageWithData:imageData];
cell.imageView.userInteractionEnabled=YES;
cell.imageView.contentMode = UIViewContentModeScaleToFill;
// cell.imageView.tag=i-1;
return cell;
}
,但我得到空的集合视图only.where我做了错误?我在控制台中获得了一系列url,但cell没有显示图像。