1

我已经继承了 UICollectionViewCell-

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

我已经为它制作了一个 xib,制作了所有 IBOutlet 集合并设置了 XIB 的类,在 Collection 视图委托方法中使用这个 Cell 时,我在尝试访问标签实例时得到一个 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

我认为您需要使用 registerNib:forCellWithReuseIdentifier: 来注册 xib,而不是注册类。试试看,看看是否有帮助。

于 2012-12-11T02:16:39.820 回答
1

如果你使用 ListCell.xib,请使用 registerNib:forCellWithReuseIdentifier:。在 awakeFromNib 而不是 initWithFrame 中实现您的 ListCell 初始值。并像这样更改类型:

- (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 回答