2013-02-07 12 views
5

私はCollectionViewアプリケーションを作成しています。ここで私はJSON文字列を通してサーバーからデータを取得しています。私の仕事の流れは次のとおりです。インスタンスに送信された認識できないセレクタの問題

  1. 作成済みのビューCellをProjectVCollectionViewCell.h、.m、.xibとして表示します。 .Hため

    コードは -

@interface ProjectCollectionViewCell:UICollectionViewCell
@property(弱い、非アトミック)IBOutlet UIImageView * projectImage。
@property(weak、nonatomic)IBOutlet UILabel * projectLabel;
@end

コードはデフォルトであり、上記の2つの変数を合成します。 と.xibは、コレクションビューのセルに上記のクラスをリンクし、「projectCell」として識別子名をリンク(イメージビューとラベルとのコレクションビューのセルを持っている。

  1. そのViewControllerをのためのコード、collectionViewが含まれている、
  2. に従うようですViewController.mのための内部

コード上記のコードcell.projectlabelで

- (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; 
} 

ですが

私に問題を与えています
[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をとります。しかし、私はこれでラベルフィールドの値を設定することができません。だから私を助けてください。

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

あなたはCollectionViewで時間を節約するためにストーリーボードを使用するように変更する必要があります場合は

+0

nibを登録しましたか? –

+0

はい。以下のようになります。 - [self.projectListView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@ "projectCell"]; – VarunJi

+0

@Sangあなたは天才です。 :)。あなたは私の命を救いました。これをあなたの答えとしてください。私はこれを解決策として扱います。 – VarunJi

答えて

2

はあなたのviewDidLoadでregisterNibしなければならない、ProjectCollectionViewCell.xibでカスタムProjectCollectionViewCellを作成します。何も登録する必要はありません。カスタムセルを選択するだけで、CollectionViewセルにドラッグ&ドロップしてIBOutletをドラッグすることができます:https://github.com/lequysang/testCollectionViewScroll

関連する問題