简体   繁体   English

UICollectionView中的垂直和水平滚动方向

[英]Both Vertical and Horizontal Scroll Direction in UICollectionView

Im stuck with the problem to use both vertical and horizontal scroll direction in a UICollectionView in the same UIViewController. 我陷入了在同一UIViewController的UICollectionView中同时使用垂直和水平滚动方向的问题。

What I've done so far is first a UICollectionView. 到目前为止,我首先要做的是UICollectionView。 In top of the UICollectionView I've got a Collection Reusable View. 在UICollectionView的顶部,我有一个Collection Reusable View。 My solution is to implement an other UICollectionView inside of the reusable view but got errors when running the project. 我的解决方案是在可重用视图中实现另一个UICollectionView,但是在运行项目时出现错误。

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath (UICollectionElementKindSectionHeader,<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) was not retrieved by calling -dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath: or is nil ((null))

So Im actually handling two different CollectionViews in one UIViewController in the same Delegate and Datasource methods. 因此,Im实际上使用相同的Delegate和Datasource方法在一个UIViewController中处理了两个不同的CollectionView。

It is a better approach to build it with a UITablewView? 用UITablewView构建它是更好的方法吗? Than add the collectionviews to different UITableViewCells? 是否将collectionviews添加到不同的UITableViewCells? Or better to start with an UIScrollView and then add two different UICollectionViews to the scrollview? 还是最好先从UIScrollView开始,然后向滚动视图添加两个不同的UICollectionViews?

在此处输入图片说明

AFTabledCollectionView AFTabledCollectionView

Refer above sample code 参考上面的示例代码

In this sample code. 在此示例代码中。 UITableView is there and UITableviewCell contains UICollectionView (With horizontal direction). UITableView在那里, UITableviewCell包含UICollectionView (水平方向)。

Some more detail from above sample code regarding to your problem 以上示例代码中有关您问题的更多详细信息

Take one 'UITableView' having 2 section. 取一个有2个部分的“ UITableView”。 Its first section would have 'UICollectionView' and second section has 'UICollectionView'. 它的第一部分为“ UICollectionView”,第二部分为“ UICollectionView”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM