Все делал по туториалу (
www.appcoda.com/ios-programming-uicollectionview-t... то есть в сториборде сделал новый UICollectionViewController с одной ячейкой (не забыл про Reuse Identifier: @"Cell"). В нее поместил UIImage с тегом 100. Затем создал класс:
#import <UIKit/UIKit.h>
@interface RecipeCollectionViewController : UICollectionViewController <UICollectionViewDelegate, UICollectionViewDataSource>
@end
#import "RecipeCollectionViewController.h"
@interface RecipeCollectionViewController (){
NSArray *recipePhotos;
}
@end
@implementation RecipeCollectionViewController
static NSString * const reuseIdentifier = @"Cell";
- (void)viewDidLoad {
[super viewDidLoad];
recipePhotos = [NSArray arrayWithObjects:@"angry_birds_cake.jpg", nil];
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = NO;
// Register cell classes
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return recipePhotos.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
recipeImageView.image = [UIImage imageNamed:[recipePhotos objectAtIndex:indexPath.row]];
return cell;
}
но в итоге получаю лишь черный экран. Xcode 6, если что.