I have a UITableView
with a UICollectionView
within each of its rows like the illustration below.
source: https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell-in-swift/
The intention of my app is to display a character set of a language within each table view row. Each character is contained within a collection view cell of the collectionview within the corresponding row.
The problem I am having is that the english character set is being displayed for every tableview row.
This is because each collectionview only has one section and thus every collectionview uses the same indexPath.section
value of zero.
What I need to do is get the section value of the table view cells that the collectionviews are within and somehow pass that to
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
I've tried several things but I can't find a way to access the tableview section value from the collectionview within it.
My code is a bit of a mess but the generally important parts are
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "HorizontalSlideCell", for: indexPath)
return cell
}
...
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "InnerCollectionViewCell",
for: indexPath as IndexPath)
//format inner collectionview cells
//indexPath.section is the collectionview section index but needs to be its parent tableview section's index. How do I get it?
cellCharLabel?.text = Languages.sharedInstance.alphabets[indexPath.section].set[indexPath.row].char
cellCharLabel?.textAlignment = .center
cellCharLabel?.font = UIFont(name: "Helvetica", size: 40)
cell.contentView.addSubview(cellCharLabel!)
return cell
}