Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 在集合视图出现滚动需求问题时加载更多数据_Swift_Uicollectionview - Fatal编程技术网

Swift 在集合视图出现滚动需求问题时加载更多数据

Swift 在集合视图出现滚动需求问题时加载更多数据,swift,uicollectionview,Swift,Uicollectionview,表视图正常工作,但collectionview也会循环 我的集合视图方法 func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { let lastSectionIndex = collectionView.numberOfSections - 1 let lastRowInde

表视图正常工作,但collectionview也会循环

我的集合视图方法

 func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
    let lastSectionIndex = collectionView.numberOfSections - 1
    let lastRowIndex = collectionView.numberOfItems(inSection: lastSectionIndex) - 1
    if indexPath.section == lastSectionIndex && indexPath.row == lastRowIndex {
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            Constants.baseUrl = self.nextPage
            self.updateData()
        }
    }
}

我的更新数据方法

func updateData() {
    HomeService.instance.getCharacterList(success: { result in
        self.CharacterListModel = CharacterListViewModel(characterlist: result!)
        self.resultArray.append(contentsOf: self.CharacterListModel.characterlist.results)
        DispatchQueue.main.async {
            self.nextPage = result?.info.next
            self.firstTableView.reloadData()
            self.gridCollectionView.reloadData()
            self.spinner.stopAnimating()
        }
    })
}