[英]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节中,您需要确定该集合视图的元素数量。
您可以通过以下方法实现此目的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.