UICollectionView中未声明的标识符错误

时间:2015-12-28 06:17:14

标签: ios objective-c uicollectionview

这是我的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

现在它给了我Undeclared identifier of Cell and Cell1的错误 不知道为什么。

3 个答案:

答案 0 :(得分:2)

像这样添加     static NSString * identifier = @" Cell&#34 ;;

// GridView1_NeedDataSource
protected void GridView1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    BindGridViewData();
}

//Bind Grid View 
private void BindGridViewData()
{
 var table = new DataTable();
         table .Columns.Add("Source");
         table .Columns.Add("Destination");
         table .Columns.Add("Date");

       if()
       {

         foreach (var item in data)
         {
            table.Rows.Add(Source,Destination,Date);
         }
         //Binding to Gridview
         GridView1.DataSource = dt;

      }
      else
      {

          GridView1.DataSource = dt; 

      }
}

答案 1 :(得分:1)

确保.xib文件中的单元格知道单元格的类型。

在界面构建器上选择单元格

enter image description here

然后在身份检查员身上。在您的情况下,它应该是cell

enter image description here

答案 2 :(得分:0)

您是否已将xib中的标识符设置为“CELL”

enter image description here

如果您使用的是自定义单元格,则需要注册您的nib / class。 你可以通过

来做到这一点
[self.myCollectionView registerNib:[UINib nibWithNibName:@"ShubhCalendarCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"ShubhCalendarCollectionViewCell"]; 

确保您的笔尖名称和标识符没有错误拼写。 希望它有所帮助。

Happyy编码.. !!