【发布时间】:2014-03-22 09:23:49
【问题描述】:
添加一个集合视图类型的对象,然后通过集合检查器建立正确的连接。
在.h文件中
IBOutlet UICollectionView *myCollection;
在viewdidload中
myCollection.delegate = self;
myCollection.dataSource = self;
数据源/委托方法是:
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection: (NSInteger)section
{
return 15;
}
// The cell that is returned must be retrieved from a call to - dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellID" forIndexPath:indexPath];
cell.backgroundColor=[UIColor greenColor];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout: (UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath * )indexPath
{
return CGSizeMake(100, 100);
}
-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath: (NSIndexPath *)indexPath
{
}
收到此错误
could not dequeue a view of kind: UICollectionElementKindCell with identifier CellID - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
我现在该怎么办...请帮我解决它..
【问题讨论】:
-
您有没有尝试过任何问题?
-
你是否设置为像 [collectionView registerClass:[HACollectionCell class] forCellWithReuseIdentifier:@"CellID"];?
-
@Natarajan 感谢您对我的支持……但请告诉我在哪里设置它
-
@Natarajan 是的,我做到了……谢谢……只需在 viewdidload [myCollection registerClass:[DetailInvoicing2 class] forCellWithReuseIdentifier:@"CellID"] 中添加这一行;
标签: ios iphone objective-c ipad uicollectionview