0

i have try to create a simple photo browser, and i used UICollectionView, when i try to insert them thumb images to the cell, it does't work,it has a thread, but i can't fixed it,please help me, thank you very very much. here is my code:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView   cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ImageCell";
ImageCell *cell = (ImageCell *)[collectionView     dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

NSArray *images =    @[@"http://www.example.com/p1.jpg",@"http://www.example.com/p2.jpg",@"http://www.example.com/p3.jpg",@"http://www.example.com/p4.jpg"];
cell.imageView.image = [UIImage imageNamed:images[indexPath.row]];

return cell;
}
Mani
  • 17,549
  • 13
  • 79
  • 100

1 Answers1

1

You can also use SDWEBIMAGE. thus you can use

[cell.imageView setImageWithURL:[NSURL URLWithString:@"Your image url"]
                   placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

see this link.

Vishal Sharma
  • 1,733
  • 2
  • 12
  • 32
  • If it`s helpful to you then Upvote it for others refrence :) cheers – Vishal Sharma Apr 07 '14 at 10:32
  • BTW,if i want add an images link array ,what should i do, i need insert many url images to the thumbs cell, – user3376284 Apr 07 '14 at 10:34
  • You can set images to the UIIMAGE and Fill your array with that UIIMAGE. Then give it to the your cell`s ImageView. – Vishal Sharma Apr 07 '14 at 10:44
  • i dont understand how to do,can't you tell me,please help me. – user3376284 Apr 09 '14 at 08:34
  • Get Your number of url`s into any array. Then [cell.imageView setImageWithURL:[NSURL URLWithString:[Yourarray objectatIndex:IndexPath.Row] ] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; – Vishal Sharma Apr 09 '14 at 08:44
  • If it`s Give you Idea about how to do it, then you can accept my answer! – Vishal Sharma Apr 09 '14 at 08:45
  • yes,I will, and my code is:'- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"ImageCell"; ImageCell *cell = (ImageCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; NSArray *images = @[@"http://www.example.com/p1.jpg",..]; [cell.imageView setImageWithURL:[NSURL URLWithString:[images objectAtIndex:indexPath.row] ] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; return cell; }'but it has a thread. – user3376284 Apr 09 '14 at 09:37
  • it seems okay.. Now whats the issue?? – Vishal Sharma Apr 09 '14 at 09:39
  • it bas a thread on the NSArray *images = @["images array urls"],what's wrong with my code? – user3376284 Apr 09 '14 at 09:42
  • You have to same or more number of objects in that array then number of rows in your TableView. – Vishal Sharma Apr 09 '14 at 09:44
  • Alloc init your Array at out of cellForItemAtIndexPath method. i.e. feed your images array in your ViewDidLoad method. – Vishal Sharma Apr 09 '14 at 09:46