简体   繁体   English

在 ViewController 中设置 TableView 和 collectionView

[英]Set TableView and collectionView in ViewController

I am building an iOS app which is having multiple collectionView some are horizontal some are vertical scroll.我正在构建一个 iOS 应用程序,它有多个 collectionView 有些是水平的有些是垂直滚动。

I wanted them to scroll vertically together I read a lot of blogs and came to know it can be done using UITableView.我希望它们一起垂直滚动我阅读了很多博客并知道可以使用 UITableView 来完成。 I was implementing UITableView and UICollectionView IN ViewController It this throwing an error.我在 ViewController 中实现了 UITableView 和 UICollectionView 这抛出了一个错误。

Error:错误:

Showing Recent Messages
The dealCollectionViewCell outlet from the BusinesViewControllerr to the UICollectionView 
is invalid. Outlets cannot be connected to repeating content. [12]

Showing Recent Messages
The dealTableViewCel outlet from the BusinesViewControllerr to the UITableViewCell is 
invalid. Outlets cannot be connected to repeating content. [12]

I am new to swift does anyone can help me in understanding this error and how to fix this.我是 swift 的新手,有没有人可以帮助我理解这个错误以及如何解决这个问题。

I have made a sample project where I made tableView and collection view different classes it works fine.我制作了一个示例项目,其中我制作了 tableView 和 collection view 不同的类,它工作正常。 I need to merge that into viewController because I am fetching some data using API from the server and need to display in my 4 different collectionView.我需要将它合并到 viewController 中,因为我正在使用 API 从服务器获取一些数据,并且需要在我的 4 个不同的 collectionView 中显示。

您应该连接 UITableView 和 UICollectionView 的插座而不是它们的单元格

Use a function in tableviewcell class and in cellforrow at call that function like:
UItableviewClass:
func BindData(data: [String]){
self.myData = data
self.myCollectionView.reloadData()
}

in ViewController:
  cellForRowAt:
   cell.BindData(data: anydata)

暂无
暂无

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

相关问题 与Swift在同一ViewController中的TableView和CollectionView - TableView and CollectionView in the same ViewController with Swift 以编程方式在 ViewController 中设置 tableView - Set tableView in a ViewController programmatically 在tableView中滚动时,如何隐藏collectionView(知道此ViewCOntroller是tableview的一半,collectionview的一半) - How can I hide a collectionView when scrolling in my tableView (knowing that this ViewCOntroller is half tableview and half collectionview) [以编程方式]选择嵌入在 collectionView 单元格中的 tableView 行时推送 viewController - [Programmatically]Push a viewController when selecting tableView row embedded in a collectionView cell 如何将约束设置为tableView到viewController中? - How to set constraints to a tableView into a viewController? 如何在tableview中设置类似collectionview的东西? - how to set up something like a collectionview in a tableview? 如何从位于 tableView 单元格内的 collectionView 的 didSelectItemAt 导航到 viewController? - How can I Navigate to a viewController from a collectionView's didSelectItemAt which is inside a tableView cell? 如何使用委托从 Tableview 单元格内的 Collectionview 单元格导航到另一个 ViewController? - How to Navigate to another ViewController from Collectionview cell which is inside Tableview cell using delegate? 将CollectionView或ViewController添加到AlertView - Add CollectionView or ViewController to AlertView 如何将CollectionView添加到ViewController - How to add a CollectionView to a ViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM