0

I am developing an App in which I have stored images through imagePicker. now i want to display same images in my collectionView. I got response as a path

path=assets/image/155/155_557b1259b8a51.jpg

when i add http://xyz.com.assets/image/155/155_557b1259b8a51.jpg then it shows error. How can i get the images through this path.Please Help me out.

M Swapnil
  • 2,361
  • 3
  • 18
  • 33
  • where are you storing image? – Syed Ali Salman Jun 15 '15 at 06:33
  • possible duplicate of [iPhone: How do I get the file path of an image saved with UIImageWriteToSavedPhotosAlbum()?](http://stackoverflow.com/questions/4457904/iphone-how-do-i-get-the-file-path-of-an-image-saved-with-uiimagewritetosavedpho) – Anbu.Karthik Jun 15 '15 at 06:35
  • @M Swapnil hi , i hope this like help you http://stackoverflow.com/questions/14496910/unable-to-load-image-from-asset-url – Ilesh P Jun 15 '15 at 06:39

1 Answers1

0

if you know the image path or name then you may implement something like this.

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell = [[UICollectionViewCell alloc]initWithFrame:CGRectMake(0, 0, 50.0, 50.0)];
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50.0, 50.0)];

    [imageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"your photo name here" ofType:@"png"]]];//if Path is from main bundle
//else
// documentDirectory URL as
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:fileName];
[imageView setImage:[UIImage imageWithContentsOfFile:filePath];
}

[cell setBackgroundView:imageView];
NSLog(@"%@",cell);
NSLog(@"Index Path = %ld",(long)indexPath.row);
return cell;
}

you also need to set delegate and datasource of UICollectionView as

[yourCollectionViewObject setDelegate:self];// if you need to use didselect or like...
[yourCollectionViewObject setDataSource:self];

and another required datasource method for returning count...

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return count;
}
Syed Ali Salman
  • 2,894
  • 4
  • 33
  • 48