我已经实现了自定义 CollectionView,但是当我运行我的应用程序时它崩溃并显示, 错误:[UICollectionViewCell Mylabel]: unrecognized selector sent to instance...
这是我的代码片段,
- (void)viewDidLoad {
[super viewDidLoad];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cvCell"];
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section { // No of Rows..
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480) //3.5"
{
return 3;
}
else // 4"
{
return 4;
}
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView { // No of Columns..
return 2;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cvCell" forIndexPath:indexPath];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CollectionViewCell" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[CollectionViewCell class]])
cell = (CollectionViewCell *)oneObject;
}
cell.Mylabel.text=@"I am label";
cell.backgroundColor= [UIColor yellowColor];
return cell;
}
我在哪里做错了?请提前帮助和thanx