[英]Undeclared identifier error in UICollectionView
This is my ViewController.m file's code for Collection view: 这是我的ViewController.m文件的Collection视图代码:
- (void)viewDidLoad
{
img = [[NSArray alloc] initWithObjects:@"1.png",@"2.png",@"3.png", nil];
name = [[NSArray alloc] initWithObjects:@"Flag",@"Blue",@"Fish", nil];
[self.collectionview registerNib:[UINib nibWithNibName:@"cell" bundle:nil] forCellWithReuseIdentifier:@"CELL"];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [img count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell1 = [collectionview dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
UIImageView *reciveimageview = (UIImageView *)[cell1 viewWithTag:100];
reciveimageview.image = [UIImage imageNamed:[img objectAtIndex:indexPath.row]];
cell1.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[img objectAtIndex:indexPath.row]]];
cell1.cellLabel.text = [name objectAtIndex:indexPath.row];
return cell1;
}
@end
Now it is giving me the error of Undeclared identifier of Cell and Cell1
Don't know why. 现在它给我一个Undeclared identifier of Cell and Cell1
的错误不知道为什么。
Add like this static NSString *identifier = @"Cell"; 像这样添加静态NSString * identifier = @“Cell”;
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *recipeImageView=(UIImageView *)[cell viewWithTag:100];
recipeImageView.image = [UIImage imageNamed:[jsonImagesArr objectAtIndex:indexPath.row]];
[cell addSubview:recipeImageView];
Have you set the identifier in xib as "CELL" 您是否已将xib中的标识符设置为“CELL”
You need to register your nib/class if you are using a custom cell. 如果使用自定义单元格,则需要注册nib / class。 You can do that by 你可以做到这一点
[self.myCollectionView registerNib:[UINib nibWithNibName:@"ShubhCalendarCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"ShubhCalendarCollectionViewCell"];
Make sure your Nib name and identifier are not mis- spelled. 确保您的笔尖名称和标识符没有错误拼写。 Hope it helps. 希望能帮助到你。
Happyy coding.. !! 快乐编码.. !!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.