Seems XCode 6 is different in using viewwithtags then XCode 5 was.
I am using the following code in XCode 6 with Storyboards. 50 cells are created but the label is not visible.Everything is set correctly like the tag etc. If I use the "old" XCode 5 way to do it with Register cell classed it seems to work for iOS 7 but in iOS 8 the data is not passed to the label until I start to scroll.
static NSString * const reuseIdentifier = @"MyCell"; - (void)viewDidLoad { [super viewDidLoad]; // Register cell classes [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier]; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 50; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; UILabel *nameLabel = (UILabel *)[cell viewWithTag:102]; nameLabel.text = @"Hello World"; nameLabel.textColor = [UIColor whiteColor]; cell.backgroundColor = [UIColor blueColor]; return cell; }
Updated answer as this works but under iOS 8 the first cell just wont display the content. Only after scrolling up and down the content is loading to the label.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"Cell"; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; UILabel *nameLabel = (UILabel *)[cell viewWithTag:102]; nameLabel.text = @"Hello World"; nameLabel.textColor = [UIColor whiteColor]; cell.backgroundColor = [UIColor blueColor]; return cell; }
Screenshots here:
https://www.dropbox.com/s/xs6gbvz3d04e4hv/Bildschirmfoto%202014-09-21%20um%2023.08.18.png?dl=0 https://www.dropbox.com/s/tp67rznggi5pcwt/Bildschirmfoto%202014-09-21%20um%2023.10.06.png?dl=0