而不是UICollectionView显示黑屏 [英] Instead of UICollectionView a black screen is displayed

查看:155
本文介绍了而不是UICollectionView显示黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新实现此处 c> c>的不定式滚动 UICollectionView 一>。对我来说遗失的东西:

I'm trying to reimplement the infinitive scrolling UICollectionView seen here. Things that were missing for me:

ViewController.h

@interface ViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate>

@end

DataCell.h

@interface DataCell : UICollectionViewCell
@property (nonatomic, strong) UILabel *label;
@end

DataCell.m

#import "DataCell.h"

@implementation DataCell

-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self){
        self.label = [[UILabel alloc] initWithFrame:self.bounds];
        self.autoresizesSubviews = YES;
        self.label.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
                                       UIViewAutoresizingFlexibleHeight);
        self.label.textAlignment = NSTextAlignmentCenter;
        self.label.adjustsFontSizeToFitWidth = YES;

        [self addSubview:self.label];
    }

    return self;
}

@end

CustomCollectionView.h :

@interface CustomCollectionView : UICollectionView

@end

对于整个项目,我使用了故事板和普通的 UIViewController 。在这个视图控制器上,我在Interface Builder中添加了一个 UICollectionView 。我将集合视图中的插座与我的视图控制器连接起来,并设置数据源并再次将方法委托给我的视图控制器。我还在Interface Builder中设置了 UICollectionViewCell 的自定义类和重用标识符。

For the whole project I used a storyboard and a normal UIViewController. On this view controller I added a UICollectionView in Interface Builder. I connected the outlet from the collection view with my view controller and set up the datasource and delegate methods again to my view controller. I also set the custom class of the UICollectionViewCell and the reuse identifier in Interface Builder.

所以一切都应该有效但是我只得到一个黑屏。我错过了什么?您可以在这里下载整个项目。

So everything should work but I only get a black screen. What I'm missing? You can download the whole project here.

推荐答案

您正在正确配置CollectionView,只是忘记了标签的颜色:)

You are configuring correctly the CollectionView, just that you forgot the color of the label :)

    [self.label setTextColor:[UIColor whiteColor]];

希望它有所帮助!

这篇关于而不是UICollectionView显示黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆