菜鸟教程小白 发表于 2022-12-11 18:19:34

ios - UICollectionReusableView 不显示


                                            <p><p>我已将 <code><UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout></code> 添加到我的 Collection View 中,并如下设置我的 <code>UICollectionView</code>。</p>

<pre><code> forCellWithReuseIdentifier:reuseIdentifier];
forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerReuseIdentifier];
</code></pre>

<p>我还添加了必要的方法。</p>

<pre><code>- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    return CGSizeMake(self.view.frame.size.width, 44.0f);
}

- (UICollectionReusableView *)supplementaryViewForElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath {
    NSLog(@&#34;supplementaryViewForElementKind called&#34;);
    if () {
      UICollectionReusableView *header = [self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
                                                                               withReuseIdentifier:headerReuseIdentifier
                                                                                    forIndexPath:indexPath];
      header.backgroundColor = ;
      return header;
    }

    return nil;
}
</code></pre>

<p>但是,<code>supplementaryViewForElementKind</code> 永远不会被调用。有什么想法吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果您已经在 Interface Builder 中添加了标题 View 并且已经分配了类,那么您应该删除代码中的 <code>registerClass</code> 调用。它应该显示出来。中断您的委托(delegate)方法以查看它被调用。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UICollectionReusableView 不显示,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/45218690/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/45218690/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UICollectionReusableView 不显示