【问题标题】:Set TableView and collectionView in ViewController在 ViewController 中设置 TableView 和 collectionView
【发布时间】:2020-03-19 04:20:01
【问题描述】:

我正在构建一个 iOS 应用,它有多个 collectionView,有些是水平的,有些是垂直滚动的。

我希望它们一起垂直滚动我阅读了很多博客并知道可以使用 UITableView 来完成。我在 ViewController 中实现 UITableView 和 UICollectionView 这会引发错误。

错误:

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]

我是新来的 swift 有没有人可以帮助我理解这个错误以及如何解决这个问题。

我制作了一个示例项目,其中我制作了 tableView 和 collection view 不同的类,它工作正常。我需要将其合并到 viewController 中,因为我正在使用 API 从服务器获取一些数据,并且需要在我的 4 个不同的 collectionView 中显示。

【问题讨论】:

  • 你需要先学会使用TableView和CollectionView。作为初学者,不要直接跳到复杂的布局。先看一些教程,把基础搞清楚。
  • 不要使用嵌套,使用单个collectionview很容易完成
  • 你可以参考这个链接collectionviewcell inside tableviewcell stackoverflow.com/questions/59043807/…

标签: ios swift uitableview uiviewcontroller uicollectionview


【解决方案1】:

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

【讨论】:

  • 好的,那怎么收集呢?
  • Could not cast value of type 'UITableViewCell' (0x7fff89793008) to 'Uriba.DealTableViewCell' 你能帮我看看这个问题是什么意思
  • 设置表格或集合视图所需了解的一切,一步一步来
  • 谢谢,我已经解决了我的问题。您分享的博客是静态视图,我正在为动态视图工作
【解决方案2】:
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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-19
    • 2020-12-11
    • 1970-01-01
    • 2016-12-12
    • 2014-12-23
    相关资源
    最近更新 更多