Reputation: 1245
I try to make a custom UICollectionViewCell in storyboard. I have CustomCell.xib, CustomCell.h and CustomCell.m. In the .xib the Classname is linked and the identifier is set to "cell". The .xib contains 1 UIImage and 2 UILabels, all having IBOutlets to the .h class.
In the ViewController where I'm using this I have a Storyboard-file, that contains the VC, that contains a UICollectionView, that contains 1 UICollectionViewCell that was changed to my "customCell" class and also got the identifier "cell".
The VC is <UICollectionViewDataSource, UICollectionViewDelegate>
and the methods are calling.
But then:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSString *identifier = @"cell";
CustomCell *cell = (CustomCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
cell.valueLabel.text = @"testtext";
cell.valueLabel.textColor = [UIColor whiteColor];
cell.titleLabel.text = @"TEST";
cell.titleLabel.textColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor grayColor];
return cell;
}
Here when I debug and keep the mouse above "cell", it shows "titleLabel = nil" and "valueLabel = nil".
Why are they not loaded?
Funny sidefact: I see some gray rectangles over black background. So SOMETHING is working. But the custom UILabels aren't there.
Upvotes: 2
Views: 705
Reputation: 119021
You have defined your cell twice, once in the XIB and once in the Storyboard. The XIB version is not used, because you never load it and provide it to the collection view. As you have named the cell in the Storyboard that is the one which is used. Your subclasses are all in the XIB so the result you see in the running app is the empty version from the Storyboard.
Choose 1 option and stick with it. If you aren't going to use the cell in other views then go with the Storyboard, if you are then go with the XIB and load and register it.
Upvotes: 1