Como definir um UILabel no UICollectionViewCell
Eu tenho um aplicativo com um UIViewController com um IBOutlet UICollectionView nele.
A célula no UICollectionView é MyCustomCell e tem esse método definindo seu UILabel:
-(void)setCellLabel:(NSString *)value{
NSLog(@"settinglabel");
cellLabel.text = @"hardcode"; //added for testing purposes
}
A célula possui o tipo de classe da propriedade, identificando-a como MyCustomCell no storyboard e também seu identificador de desenfileiramento. O UIViewController adota a fonte de dados e delegar protocolos. O IBOutlet UILabel tem sua saída cellLabel conectada ao storyboard. Os métodos são definidos 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;
}
Eu recebo três células desenhadas na minha tableview, correspondendo aos 3 objetos da minha matriz. A matriz simplesmente contém objetos string que eu estava definindo diretamente por objectAtIndexPath, mas eu decidi configurá-lo diretamente para @ "hi", uma vez que não estava funcionando. Eu até alterei o valor usado no método setCellLabel para um valor codificado e continuo recebendo apenas a string default "Label" em cada célula.
Por que o cellLabel não está sendo configurado corretamente?