发送到实例的无法识别的选择器中的问题

时间:2013-02-07 14:57:58

标签: uicollectionview uicollectionviewcell

我正在创建一个CollectionView应用程序。我从服务器通过JSON字符串获取数据。我的工作流程如下

  1. 创建集合视图单元格作为ProjectVCollectionViewCell.h,。m,.xib。

    .h的代码是 -

  2.   

    @interface ProjectCollectionViewCell:UICollectionViewCell
          @property(弱,非原子)IBOutlet UIImageView * projectImage;
          @property(弱,非原子)IBOutlet UILabel * projectLabel;
          @end

    .m的代码是默认的,并合成了上述2个变量。 和.xib具有带有图像视图和标签的集合视图单元格(将上面的类与集合视图单元链接,并将标识符名称链接为“projectCell”。

    1. 其ViewController的代码,包含collectionView,如下
    2. ViewController.m中的代码是

      - (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section{
          return [projectList count];
      }
      - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
      {
          ProjectCollectionViewCell *cell = (ProjectCollectionViewCell *)[cv dequeueReusableCellWithReuseIdentifier:@"projectCell" forIndexPath:indexPath];    
      
          cell.projectLabel.text = @"";//Here i am getting issue
          //cell.projectLabel.text = [[NSString alloc] initWithString:[[projectList objectAtIndex:indexPath.row] objectForKey:@"albumName"]];        
          return cell;
      }
      
      在上面代码中的

      cell.projectlabel给了我一个问题

      [UICollectionViewCell projectLabel]: unrecognized selector sent to instance 0x75f0fb0
      2013-02-07 20:08:17.723 Sample[3189:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell projectLabel]: unrecognized selector sent to instance 0x75f0fb0'
      *** First throw call stack:
      

      单元格值很好,我用NSLog跟踪它,代码提示也在“。”之后使用projectLabel。但是我无法通过此设置标签字段值。所以请帮帮我。

1 个答案:

答案 0 :(得分:2)

在使用ProjectCollectionViewCell.xib创建自定义ProjectCollectionViewCell的情况下,您必须在viewDidLoad中注册NFS:

[self.projectListView registerNib:[UINib nibWithNibName:@"ProjectCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"projectCell"];

您应该使用StoryView更改为使用StoryBoard节省时间。不需要注册任何内容,只需选择customCell,将所需的所有内容拖放到CollectionView单元格中并拖动IBOutlet:https://github.com/lequysang/testCollectionViewScroll

相关问题