Collection view supplementary view not showing but i had implemented iOS swift

Problem: 

I had registered supplementary view but it was not showing.Also it was not showing error rxswift.

My code as like below.

    func setupRxBinding() {

        //Collection bind

            

        collDataSource = RxCollectionViewSectionedReloadDataSource<SectionOfCollection>(

                configureCell: { (_, collectionView, indexPath, item) in

        // my cell configuration

        })

            

        model.items.bind(tomycollView.rx.items(dataSourcecollDataSource)).disposed(bydisposeBag)

        

        mycollView.rx.itemSelected

            .subscribe(onNext: { [weak self] indexPath in

                

            }).disposed(bydisposeBag)


        mycollView.rx.setDelegate(self).disposed(bydisposeBag)



        collDataSource.configureSupplementaryView = { dataSource, collectionView, kind, indexPath in

            guard kind == UICollectionView.elementKindSectionHeader else {

                fatalError("Unexpected supplementary view kind")

            }

            let headerView = collectionView.dequeueReusableSupplementaryView(

                ofKind: kind,

                withReuseIdentifier"HeaderCell",

                for: indexPath

            ) asHeaderCell

            

            return headerView

        }


}



Solution:

Oh.Okay you are code is right.But you have to configureSupplementaryView before binding.Then onnly it will works.



    func setupRxBinding() {

        //Collection bind

            

        collDataSource = RxCollectionViewSectionedReloadDataSource<SectionOfCollection>(

                configureCell: { (_, collectionView, indexPath, item) in

        // my cell configuration

        })


// this code

        collDataSource.configureSupplementaryView = { dataSource, collectionView, kind, indexPath in

            guard kind == UICollectionView.elementKindSectionHeader else {

                fatalError("Unexpected supplementary view kind")

            }

            let headerView = collectionView.dequeueReusableSupplementaryView(

                ofKind: kind,

                withReuseIdentifier"HeaderCell",

                for: indexPath

            ) asHeaderCell

            

            return headerView

        }


            

        model.items.bind(tomycollView.rx.items(dataSourcecollDataSource)).disposed(bydisposeBag)

        

        mycollView.rx.itemSelected

            .subscribe(onNext: { [weak self] indexPath in

                

            }).disposed(bydisposeBag)


        mycollView.rx.setDelegate(self).disposed(bydisposeBag)




}


You have to change the code as like above then it will works good..Happy coding....


Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift