Skip to content

Instantly share code, notes, and snippets.

@badeen
Created November 2, 2012 22:49
Show Gist options
  • Save badeen/4004835 to your computer and use it in GitHub Desktop.
Save badeen/4004835 to your computer and use it in GitHub Desktop.
- (NSInteger)numberOfSectionsInCollectionView:(PSTCollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(PSTCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [_photos count];
}
- (PSTCollectionViewCell *)collectionView:(PSTCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
PSTCollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:PhotoCellIdentifier forIndexPath:indexPath];
UIImageView *imageView = (UIImageView *)[cell.contentView viewWithTag:42];
if (!imageView) {
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MBPlaceholderFacebookAlbum"]];
imageView.tag = 42;
imageView.frame = cell.contentView.bounds;
imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:imageView];
}
NSLog(@"row: %i; count: %i", indexPath.row, [_photos count]); // prints "row: 26; count: 25"
NSDictionary *photo = [_photos objectAtIndex:indexPath.row];
NSURL *photoURL = [NSURL URLWithString:photo[@"picture"]];
NSMutableURLRequest *photoURLRequest = [NSMutableURLRequest requestWithURL:photoURL];
[imageView setImageWithURLRequest:photoURLRequest placeholderImage:[UIImage imageNamed:@"MBPlaceholderFacebookAlbum"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
imageView.image = [image imageCroppedToFitSize:CGSizeMake(MB_PHOTO_ALBUM_PHOTO_SIZE, MB_PHOTO_ALBUM_PHOTO_SIZE)];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
}];
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment