Ios UICollectionView补充视图初始化在滚动中被反复调用

Ios UICollectionView补充视图初始化在滚动中被反复调用,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,在UICollectionView中,我有一个补充标题。一开始一切正常,然后当我使用应用程序时,我的头单元格中的init方法似乎在每次滚动时都会被调用,它会变得滞后。我可以判断出一些错误,因为每当我像这样滚动标题时,标题中视图上的阴影就会再次附着 这里是我设置标题的地方 switch kind { case UICollectionView.elementKindSectionHeader: let header = collectio

在UICollectionView中,我有一个补充标题。一开始一切正常,然后当我使用应用程序时,我的头单元格中的init方法似乎在每次滚动时都会被调用,它会变得滞后。我可以判断出一些错误,因为每当我像这样滚动标题时,标题中视图上的阴影就会再次附着

这里是我设置标题的地方

switch kind {

            case UICollectionView.elementKindSectionHeader:

                let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "feeds", for: indexPath) as! ChangeFeedCell
                header.feedsButton.addTarget(self, action: #selector(showFeeds), for: .touchUpInside)
                header.typeButtonWhole.addTarget(self, action: #selector(changeFeeds), for: .touchUpInside)
                header.topButtonWhole.addTarget(self, action: #selector(changeTopSort), for: .touchUpInside)
                
                feedLabelsDelegate = header
                return header

            case UICollectionView.elementKindSectionFooter:
                let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Footer", for: indexPath) as! LoadingFooterCell
                showLoaderDelegate = footer
                footer.backgroundColor = .clear
                return footer
            default:

                fatalError("Unexpected element kind")
            }

您是否使用
register(quo:forSupplementaryViewOfKind:withReuseIdentifier:)
?@AdamPro13是的-
collectionView.register(ChangeFeedCell.self,forSupplementaryViewOfKind:UICollectionView.elementKindSectionHeader,withReuseIdentifier:“feed”)