繁体   English   中英

我是否可以根据tableView部分iOS Swift更改collectionView中的单元格数量?

[英]Can i change the number of cells in collectionView based on the tableView Section iOS Swift?

我有2个数组

var list3:Array< String > = Array < String >()
var list4:Array< String > = Array < String >()

如果tableview Section为0,我需要返回列表3的计数

如果tableview Section为4,我需要返回列表4的计数

我怎样才能做到这一点 ?

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        switch(section){
             case 0 : return list3.count
             case 1 : return list4.count
             default : return 0
          }
    }

它不起作用...

在创建UITableViewCell时,在UITableViewController的重写功能中,您将从indexPath中获得该部分和该行,并将在单元格内设置集合视图

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
  let cell = ...
  if(indexPath.row == 3 && indexPath.section == 1){
     cell.numberOfCells = 123
   }
  }

阅读您的问题以及一些评论和您的答案,我的理解是:

您有一张桌子视图; 在该表格视图中,表格视图单元格(TVC)之一具有集合视图。 并且基于此TVC是在第0节还是第1节中,您需要确定该集合视图的元素数量。

您可以通过以下方法实现此目的:

  • 创建TVC时,将收集视图的标签值设置为适当的区号。
  • 然后,基于此标记,您可以决定是使用list3还是list4填充集合视图。
  • 如果我对您的问题和建议的解决方案的理解很好,并且您需要代码段,请告诉我,我将添加它。 谢谢。

暂无
暂无

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

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