5

CollectionViewアプリを作成しています。ここで、JSON文字列を介してサーバーからデータをフェッチしています。私のワークフローは次のとおりです

  1. コレクションビューセルをProjectVCollectionViewCell.h、.m、.xibとして作成しました。

    .hのコードは-

@interface ProjectCollectionViewCell:UICollectionViewCell
@property(weak、nonatomic)IBOutlet UIImageView * projectImage;
@property(weak、nonatomic)IBOutlet UILabel * projectLabel;
@終わり

.mのコードはデフォルトであり、上記の2つの変数を合成します。.xibには、画像ビューとラベルを含むコレクションビューセルがあります(上記のクラスをコレクションビューセルにリンクし、識別子名を「projectCell」としてリンクしました。

  1. そのViewControllerのコードは、collectionViewを含み、次のとおりです。

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も取得していることを確認しました。しかし、これではラベルフィールドの値を設定できません。だから私を助けてください。

4

1 に答える 1

2

ProjectCollectionViewCell.xibを使用してカスタムProjectCollectionViewCellを作成する場合は、viewDidLoadにNibを登録する必要があります。

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

CollectionViewで時間を節約するには、StoryBoardを使用するように変更する必要があります。何も登録する必要はありません。customCellを選択し、必要なものをすべてCollectionViewセルにドラッグアンドドロップして、IBOutletをドラッグします:https ://github.com/lequysang/testCollectionViewScroll

于 2013-02-07T15:39:55.647 に答える