且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有UICollectionViewController的情况下使用UICollectionView

更新时间:2022-10-16 10:00:25

当然你可以使用 UICollectionView 而不用 UICollectionViewController



只需创建一个 UICollectionViewLayout ,然后调用

   - (id)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout 

创建 UICollectionView 的新实例。不要忘记将 UICollectionView 的委托和数据源设置为您的类,并实现 UICollectionViewDataSource 协议。 / p>

希望有所帮助。


Normaly, if we want to use UICollectionView, we must use an UICollectionViewController. But now I don't want, so how can I use UICollectionView without an UICollectionViewController?

Of course you can use a UICollectionView without an UICollectionViewController.

Just create a UICollectionViewLayout of your choice, and then call

- (id)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout

to create a new instance of UICollectionView. Don't forget to set the delegate and datasource of the UICollectionView to your class, and implement the UICollectionViewDataSource protocol.

Hope that helps.