Ios tableviewcell中uicollectionviewcells中的选择数存在问题
当我想在UITableViewCell中返回一定数量的UICollectionViewCell时,它的行为非常奇怪,我就是想不出问题所在,在前三个单元格开始变得一团糟之后,它开始返回与前两个相同的值,以便更好地解释: 变量计数:[Int]=[2,3,4,5,6] -第一个UITableViewCell根据计数数组为我提供2个uicollectionviews。 -第二个UITableViewCell根据计数数组提供3个uicollectionviews。 -第三个UITableViewCell根据计数数组为我提供了4个uicollectionviews。 -第四个UITableViewCell给我2个uicollectionviews,根据我的计数数组,它应该是5,但它决定不这样做。 -第五个UITableViewCell给我3个uicollectionviews,根据我的计数数组,它应该是6,但它决定不这样做Ios tableviewcell中uicollectionviewcells中的选择数存在问题,ios,swift,Ios,Swift,当我想在UITableViewCell中返回一定数量的UICollectionViewCell时,它的行为非常奇怪,我就是想不出问题所在,在前三个单元格开始变得一团糟之后,它开始返回与前两个相同的值,以便更好地解释: 变量计数:[Int]=[2,3,4,5,6] -第一个UITableViewCell根据计数数组为我提供2个uicollectionviews。 -第二个UITableViewCell根据计数数组提供3个uicollectionviews。 -第三个UITableViewCell根
- 我已经尝试过使计数数组基于我自己单独的int值,并且它仍然做相同的事情
- 我尝试过使用编程的uicollectionview,而不是使用故事板,它只是做了同样的事情
override func viewDidLoad() {
super.viewDidLoad()
SetUp()
}
func SetUp() {
self.definesPresentationContext = true
}
}
扩建项目{
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let Cell: TableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewCell
print(indexPath.row)
Cell.CollectionCount = Count[indexPath.row]
Cell.ProjectText = "Hello"
return Cell
}
}
类TableViewCell:UITableViewCell、UICollectionViewDelegate、UICollectionViewDataSource{
@IBOutlet weak var ProjectLabel: UILabel!
@IBOutlet weak var CollectionView: UICollectionView!
var ProjectText: String?
var CollectionCount: Int?
override func layoutSubviews() {
super.layoutSubviews()
ProjectLabel.text = ProjectText!
CollectionView.delegate = self
CollectionView.dataSource = self
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return CollectionCount!
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let Cell: UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
return Cell
}
}
- 第一个UITableViewCell应该为我提供2个uicollectionviews
- 第二个UITableViewCell应该为我提供3个uicollectionviews
- 第三个UITableViewCell应该为我提供4个uicollectionviews
- 第四个UITableViewCell应为我提供5个uicollectionviews
- 第五个UITableViewCell应该为我提供6个uicollectionviews
count
属性时,需要重新加载集合视图;使用didSet
观察者。此外,按照惯例,Swift变量和属性以小写字母开头。类、结构和协议以大写字母开头。采用此约定将使您的代码对其他人更清晰。单元格将被重用。更改count
属性时,需要重新加载集合视图;使用didSet
观察者。此外,按照惯例,Swift变量和属性以小写字母开头。类、结构和协议以大写字母开头。采用此约定将使您的代码对其他人更清晰。