你如何做到这一点?解决方法 1)将UICollectionVIEw拖到UIVIEw中并适当调整大小。
2)创建一个属性,它也是您的.h文件中的集合视图中的IBOutlet:
@property (nonatomic,retain) IBOutlet UICollectionVIEw *myCollectionVIEw;
3)再次在.h文件中声明你的代表,所以现在你的.h应该看起来像这样:
@interface UtaQuickVIEw : UIVIEwController <UICollectionVIEwDataSource,UICollectionVIEwDelegate> {}@property (nonatomic,retain) IBOutlet UICollectionVIEw *myCollectionVIEw;
4)将myCollectionVIEw IBOutlet连接到你的故事板中。
5)(可选)如果您的目标是iOS6以上的版本,可合成myCollectionVIEw属性。如果您的目标是iOS6,它将为您自动合成。这适用于所有属性,而不仅仅是UICollectionVIEws。所以在iOS6中,你根本不需要@synthesize myCollectionVIEw = _myCollectionVIEw。您可以随时使用_mycollectionvIEw访问该属性。
6)在.m文件vIEwDIDLoad中,设置你的委托和dataSource。
_myCollectionVIEw.delegate = self;_myCollectionVIEw.dataSource = self;
7)实现所需的dataSource方法:
#pragma mark - UICollectionVIEw DataSource - (NSInteger)collectionVIEw:(UICollectionVIEw *)collectionVIEw numberOfItemsInSection:(NSInteger)section - (UICollectionVIEwCell *)collectionVIEw:(UICollectionVIEw *)collectionVIEw cellForItemAtIndexPath:(NSIndexPath *)indexPath
从那里,您可以根据需要实现尽可能多的UICollectionVIEwDelegate方法。但是,根据文档需要2个:
#pragma mark - UICollectionVIEwDelegate- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDEnddisplayingCell:(UICollectionVIEwCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDEnddisplayingSupplementaryVIEw:(UICollectionReusableVIEw *)vIEw forElementOfKind:(Nsstring *)elementKind atIndexPath:(NSIndexPath *)indexPath
请注意,您可以替换< UICollectionVIEwDelegateFlowLayout>为< UICollectionVIEwDelegate>并且仍然可以访问< UICollectionVIEwDelegate>中的所有方法。因为< UICollectionVIEwDelegateFlowLayout>是< UICollectionVIEwDelegate>的子类。
UICollectionViewDataSource Protocol Documentation
UICollectionViewDelegate Protocol Documentation
总结以上是内存溢出为你收集整理的xcode – UIView中的UICollectionView全部内容,希望文章能够帮你解决xcode – UIView中的UICollectionView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)