我有一个UIViewController
包含一个CollectionView
但输出全白的
在 GridViewController.h
#import <UIKit/UIKit.h>
@interface GridViewController : UIViewController <UICollectionViewDataSource,
UICollectionViewDelegate>{
}
@property (nonatomic, strong)UIImageView *imageHeader;
@property (nonatomic, strong)UIButton * buttonHome;
@property (nonatomic, strong)UILabel * labelTitle;
@property (nonatomic, strong)UICollectionView * collectionView;
//....
@end
在 GridViewController.m
- (void)viewDidLoad
{
//....
[self.collectionView registerClass:[UICollectionView class]
forCellWithReuseIdentifier:@"Cell"];
NSLog(@"%@", self.collectionView);//here (null), why?
self.collectionView.delegate=self;
self.collectionView.dataSource=self;
//...
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:
(NSInteger)section;
{
return 32;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:
(NSIndexPath *)indexPath{
NSString *kCellID = @"cellID";
CollectionViewCellCustom *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
cell.imageView.backgroundColor =[UIColor greenColor];
return cell;
}