Cómo configurar un UILabel en UICollectionViewCell
Tengo una aplicación con un UIViewController con un UICollectionView IBOutlet en ella.
La celda en UICollectionView es MyCustomCell y tiene este método configurando su UILabel:
-(void)setCellLabel:(NSString *)value{
NSLog(@"settinglabel");
cellLabel.text = @"hardcode"; //added for testing purposes
}
La celda tiene el tipo de clase de propiedad que lo identifica como MyCustomCell en el guión gráfico y su identificador de salida también. El UIViewController adopta la fuente de datos y los protocolos delegados. El IBOutlet UILabel tiene su salida cellLabel conectada al guión gráfico. Los métodos se definen como:
- (void)viewDidLoad{
[super viewDidLoad];
self.restNames = @[@"Orange",@"Naranja",@"Narnia"];
[self.collectionView registerClass:[MyCustomCell class] forCellWithReuseIdentifier:@"MyCustomCellID"];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
NSLog(@"%d",[self.restNames count]);
return [self.restNames count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
MyCustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
[cell setCellLabel:@"hi"];
NSLog(@"fitsname %@",[self.restNames objectAtIndex:indexPath.row]);
return cell;
}
Obtengo tres celdas dibujadas en mi vista de tabla, correspondientes a los 3 objetos en mi matriz. La matriz simplemente contiene objetos de cadena que estaba configurando directamente por objectAtIndexPath pero decidí configurarlo directamente en @ "hi" ya que no estaba funcionando. Incluso cambié el valor utilizado en el método setCellLabel a un valor codificado y sigo obteniendo solo la cadena predeterminada "Etiqueta" en cada celda.
¿Por qué no se configura correctamente el cellLabel?