UICollectionView в UICollectionView reloadData на AppleTV - PullRequest
2 голосов
/ 25 октября 2019

Я разрабатываю приложение AppleTV.

У меня есть UICollectionView внутри UICollectionView cell.

Когда данные обновляются, CollectionView, помещенный в ViewController, являетсяreloadData, и в то же время CollectionView в CollectionView также равно reloadData.

Тогда фокус не возвращается в исходное положение в CollectionView.

CollectionView, помещенный в ViewController - canFocusItemAt false.

Что мне делать?

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        if collectionView === self.collectionView {
            return 10
        } else {
            return 10
        }
    }

    func collectionView(_ collectionView: UICollectionView, canFocusItemAt indexPath: IndexPath) -> Bool {
        if collectionView === self.collectionView {
            return false
        } else {
            return true
        }
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        if collectionView === self.collectionView {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "aaaa", for: indexPath)
            if let collectionView = cell.viewWithTag(20) as? UICollectionView {
                collectionView.delegate = self
                collectionView.dataSource = self
                collectionView.reloadData()
            }
            return cell
        } else {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "bbbb", for: indexPath)
            return cell
        }
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        self.collectionView.reloadData()
    }
...