1

UICollectionViewCellをサブクラス化しました-

@interface ListCell : UICollectionViewCell
@property(nonatomic,strong) IBOutlet UILabel *lblAppName;
@end

同じためにxibを作成し、すべてのIBOutletコレクションを作成し、XIBのクラスを設定しました。コレクションビューデリゲートメソッドでこのセルを使用しているときに、ラベルインスタンスにアクセスしようとするとnill値を取得します。

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {

ListCell *cell = (ListCell *)[cv dequeueReusableCellWithReuseIdentifier:@"ListCell" forIndexPath:indexPath];
AppDetails *temp=[arrApplist objectAtIndex:indexPath.item];
cell.lblAppName.text=temp.strName;
return cell;
}

セルをコレクションビューに登録しました:

[collectionView registerClass:[ListCell class] forCellWithReuseIdentifier:@"ListCell"];

私が見逃しているかもしれない何か他のものはありますか?前もって感謝します。

4

2 に答える 2

1

ListCell.xibを使用する場合は、registerNib:forCellWithReuseIdentifier:を使用してください。ListCellの初期値をinitWithFrameではなくawakeFromNibに実装します。そして、そのようにタイプを変更します。

- (ListCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ListCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"ListCell" forIndexPath:indexPath];
cell.lblAppName.text=(NSString *); 
return cell; 
}
于 2012-12-11T15:33:45.107 に答える
1

クラスを登録する代わりに、registerNib:forCellWithReuseIdentifier: を使用して xib を登録する必要があると思います。それを試して、それが役立つかどうかを確認してください。

于 2012-12-11T02:16:39.820 に答える