如何在没有UICollectionViewController的情况下使用UICollectionView [英] how can we use UICollectionView without an UICollectionViewController

查看:109
本文介绍了如何在没有UICollectionViewController的情况下使用UICollectionView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Normaly,如果我们想使用 UICollectionView ,我们必须使用 UICollectionViewController 。但现在我不想要,所以如何在没有 UICollectionViewController 的情况下使用 UICollectionView

解决方案

当然你可以使用 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.

这篇关于如何在没有UICollectionViewController的情况下使用UICollectionView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆