【问题标题】:UICollectionViewCell Subclass issueUICollectionViewCell 子类问题
【发布时间】:2012-12-11 01:09:19
【问题描述】:

我已经继承了 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"];

还有什么我可能遗漏的吗? 提前致谢。

【问题讨论】:

    标签: objective-c ios6 uicollectionview uicollectionviewcell


    【解决方案1】:

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

    【讨论】:

    • 您好,谢谢,但必须同时注册课程和 xib
    【解决方案2】:

    如果你使用 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; 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-14
      • 2013-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多