Xcode 6 UICollectionview viewwithtag not working

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

+5
source share
2 answers

I found the solution in the same way as before. Delete the row to register the cell and place the reuse identifier where you are processing the cell. Sorry for my late reply to this

+4
source

I had a similar problem when I used Xcode 6.3 beta and iOS 8. I solved it like this. First, select a view and turn off Partitions by size in the storyboard. Then clean and create the application. After that, enable dimension classes . Now it will work.

+3
source

Source: https://habr.com/ru/post/1203087/


All Articles