J'essaie de créer une vue simple: une tableView qui prend comme 80% de l'écran, et une collectionView avec 4 lignes en bas. Tout fonctionne bien avec ma tableView mais je ne peux pas faire les choses correctement avec ma collectionView. Je reçois toujours l'exception suivante:Exception lors de la création de collectionViewCell
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'could not dequeue a view of kind: UICollectionElementKindCell with
identifier simpleCollectionCell - must register a nib or a class for the
identifier or connect a prototype cell in a storyboard'.
J'ai cherché dans mon View Controller: il y a 2 points de référenceurs pour mon CollectionView: délégué et source de données. Donc c'est bien. Et j'utilise la méthode "withReuseIdentifier" donc je n'ai pas besoin de déclarer un identifiant dans la plume. J'ai essayé de créer une propriété pour collectionView, mais cela ne change rien.
Je ne vois vraiment pas ce que je suis absent ...
.h:
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController <UITableViewDelegate,
UITableViewDataSource, UICollectionViewDelegate, UICollectionViewDataSource>
@end
.m:
#import "MainViewController.h"
@interface MainViewController()
@end
@implementation MainViewController {
NSArray *recipes;
NSArray *images; }
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self; }
- (void)viewDidLoad {
[super viewDidLoad];
recipes = [NSArray arrayWithObjects:@"Label1", @"Label2", @"Label3", @"Label4", @"Label5", @"Label6", @"Label7", @"Label8", @"Label9", @"Label10", @"Label11", @"Label12", @"Label13", @"Label14", @"Label15", nil];
images = [NSArray arrayWithObjects:@"img1", @"img2", @"img3", @"img4", nil];
// Do any additional setup after loading the view. }
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated. }
#pragma mark TableView methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [recipes count]; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [recipes objectAtIndex:indexPath.row];
return cell;
}
#pragma mark CollectionView methods
- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection: (NSInteger)section {
return [images count];
}
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView
dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
return cell;
}
@end
Merci à l'avance!
chèque story-board, vous n'avez pas identifiant donné pour la cellule de collecte « cellule ». – Pawan