Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instead of UICollectionView a black screen is displayed

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 

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.

like image 374
testing Avatar asked Mar 31 '15 10:03

testing


1 Answers

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

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

enter image description here

Hope it helps!

like image 99
Javier Flores Font Avatar answered Oct 13 '22 05:10

Javier Flores Font