XCode 6 UICollectionview viewwithtag无法正常工作

Ben*_*Ben 5 ios uicollectionview uicollectionviewcell viewwithtag xcode6

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

我在XCode 6中使用以下代码与Storyboard.创建了50个单元格,但标签不可见.所有内容都设置正确,如标签等.如果我使用"旧"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;
}
Run Code Online (Sandbox Code Playgroud)

更新后的答案,但在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;
}
Run Code Online (Sandbox Code Playgroud)

屏幕截图:

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*_*Ben 4

我找到了解决方案,就像我以前那样做。删除用于注册单元的行,并将reuseIdentifier 放在处理单元的位置。抱歉我对此回复晚了