It seems that Xcode 6 is different when using viewwithtags, then Xcode 5 was.
I am using the following code in Xcode 6 with Storiesboards. 50 cells created, but the label is not visible. Everything is configured correctly, like a tag, etc. If I use the “old” Xcode 5 way to do this with the Register cell class, it seems to work for iOS 7, but in iOS 8 the data is not passed to the label until I start scrolling.
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 it works, but in iOS 8 the first cell just doesn't display the content. Only after scrolling up and down is the content loaded onto 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
source share