我有一個UITableView
與UICollectionView
其中每行如下圖所示。如何從兒童內部獲取UITableView的部分UICollectionview
源:https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell-in-swift/
我的應用程序的目的是爲了顯示一個字符集的每個表視圖行內的語言。每個字符都包含在相應行內collectionview的集合視圖單元中。
我遇到的問題是英文字符集正在顯示,每行的tableview。
這是因爲每個collectionview只有一個部分,因此每個collectionview使用相同的indexPath.section
值爲零。
我需要做的就是表視圖細胞的collectionviews是內並以某種方式傳遞到
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
我已經試過幾件事情的區間值,但我不能找到一種方法從其中的collectionview訪問tableview部分的值。
我的代碼是一個有點亂,但一般重要的部分是
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
}
乾杯。正是我在找的! – Danoram
如果我們在集合視圖中傳遞標籤,但由於可重用的表視圖單元格,我正在獲取上一個單元格和以前的標籤。 – user1960279
@ user1960279你在'''cell.collectionView.tag = indexPath.row'後面看到collectionView的標籤被重新分配了。你在哪裏使用標籤? –