I created a collection view very simple to an Apple collection view sample project. I have a collection view in a view controller in storyboard, and set a label inside the collection view cell in the top right part of the collection view. I've hooked that up to the IBOutlet in my custom cell. Here's the relevant code:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.workoutView registerClass:[Cell class] forCellWithReuseIdentifier:@"Cell"];
...
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if (collectionView == self.collView) {
Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
cell.segmentTitle.text = @"some text";
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
return nil;
}
I put a breakpoint after the segmentTitle.text
part and segmentTitle is always null. Accordingly what I see in the simulator is empty white boxes. What did I miss?
UICollectionViewCell inside StoryBoard don't need to registerClass, just choose reuseidentifier in StoryBoard. Delete this line:
// [self.workoutView registerClass:[Cell class] forCellWithReuseIdentifier:@"Cell"];
And make sure you connect right way:
-Select class type of UICollectionViewCell in storyBoard to Cell
-Drag UILabel into Cell and hook up to Cell.h
-Type the reuse identifier
MainFeedCollectionView.registerClass(CollectionViewCell.self, forCellWithReuseIdentifier: "CollectionViewCell")
I removed this line from my code now its now working fine...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With