【问题标题】:load UICollectionViewCell to UIView将 UICollectionViewCell 加载到 UIView
【发布时间】:2015-10-05 10:45:27
【问题描述】:

我试图将 UICollectionViewCell 从 .xib 加载到 UICollectionView,它也在 .xib 中的可重用 UIView 中。这个 UIView 将被加载到更多的 UIViewControllers。我发现,我需要这样的称重传感器:

[self.collectionView registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellWithReuseIdentifier:@"CELL"];

但它不会加载它。 我在网上四处寻找答案,但找不到这个具体案例。

【问题讨论】:

    标签: ios uiview uiviewcontroller uicollectionview uicollectionviewcell


    【解决方案1】:

    有两种不同的情况,

    1) 如果您使用故事板和自定义单元格。

    2) Nib 和简单的 UIView(UIView 的层次结构)。

    你的似乎是第二种情况, 首先,您需要创建 UICollectionView 的实例(通过 alloc init 方法)。 然后使用以下方法注册持有您的单元格/视图的 Nib。

    [self.collectionView registerNib:[UINib nibWithNibName:CELL_IDENTIFIER bundle:nil] forCellWithReuseIdentifier:CELL_IDENTIFIER];
    

    然后你可以使用下面的方法使用那个笔尖

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell;
    cell = (UICollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:CELL_IDENTIFIER
                                                                            forIndexPath:indexPath];
    //Populate your data here.
    return cell;
    

    }

    希望这会有所帮助.. :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      • 2011-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多