我试图在Xcode 6上使用UICollectionViewController
,但我无法看到自定义单元格或原型项目。我把Label放在白色的单元格中,我实现了numberOfSections和numberOfItemsInSection,但是问题仍然存在。可以帮我?提前谢谢。
@implementation CollectionViewController
static NSString * const reuseIdentifier = @"Cell";
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = NO;
// Register cell classes
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
#warning Incomplete method implementation -- Return the number of sections
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete method implementation -- Return the number of items in the section
return 5;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
// Configure the cell
return cell;
}
答案 0 :(得分:0)
您可以尝试在cellForItemAtIndexPath
我的代码的小例子
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MEMediaView *cell = [cv dequeueReusableCellWithReuseIdentifier:@"MEMediaView" forIndexPath:indexPath];
[cell awakeFromNib];
[cell setMemryMediaData:[mediaArray_ objectAtIndex:indexPath.row]];
[cell setMediaContent];
if (shadow)
{
[cell shadeCoverImage];
}
return cell;
}
另外不要忘记设置代理:
self.collectionView.delegate = self;
self.collectionView.dataSource = self;