5

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

Ben
  • 650
  • 2
  • 12
  • 23
  • 2
    You shouldn't register the class if the cell was made in a storyboard (that goes for iOS 7 or 8). If you register the class, you will get the default basic cell. – rdelmar Sep 21 '14 at 19:11
  • 1
    Thanks. I didn't register the class now but the problem under iOS 8 is that the label is not updated with the content when the collectionview is loaded. The cells are starting to update with the content when I start to scroll. – Ben Sep 21 '14 at 21:00
  • 1
    Hi. I found the solution in doing it the way like I did before. Remove the line to register the cell and put the reuseIdentifier where you handle the cell. Sorry for my late response on this. – Ben Oct 16 '14 at 17:56
  • I think thats the same thing @rdelmar suggested in a first place. – rohan-patel Jul 14 '15 at 18:10

2 Answers2

4

I found the solution in doing it the way like I did before. Remove the line to register the cell and put the reuseIdentifier where you handle the cell. Sorry for my late response on this

Ben
  • 650
  • 2
  • 12
  • 23
  • Yep, I had the same problem I think where I registered the cell programmatically but also set the cell name in Interface Builder and that broke things. Deleted the programmatic ones and everything was fine. – TenaciousJay Nov 11 '14 at 18:14
  • I had the same problem as well and this solution worked for me - I don't know why this is the case as the registerForClass selector is include in the auto generated code. – Sean Dev Jan 22 '15 at 17:30
3

I had similar problem when I was using Xcode 6.3 beta and IOS 8. I solved it like this. First select view and disable the Size Classes in Storyboard. Then clean and build the app. After that enable the Size Classes . It will work now.

Vineeth Joseph
  • 5,177
  • 3
  • 17
  • 31
  • Did you file a radar on this? This is still a problem in Xcode 6.3.2 and I'd love to dupe it. Also, have you tested whether this is an issue in Xcode 7? – jpittman Jun 16 '15 at 23:06