내 IOS 코드를 Swift 4로 마이그레이션했으며 내 콜렉션 뷰에서 데이터로드 방법을 다시 사용할 수 없습니다. 나는 많은 것을 수색하고 시도했지만 아무도 일을하지 않았다. 스위프트 3에서 한 달 이상 완벽하게 작동 했으므로 어떤 일이 발생하는지 알지 못합니다.UICollectionView 재로드 데이터가 신속하게 작동하지 않습니다. 4
이 코드는 사례 중 하나입니다 : 버튼을 클릭 할 때이 함수를 호출
private func setLevelLessons(){
let operationsDB = DBOperations()
self.indexInformation = operationsDB.getIndex(forLevel: self.currentLevel)
self.numLessons = (self.indexInformation?.count)!
DispatchQueue.main.async {
self.lessonsCollectionView.reloadData()
}
}
. 클릭하면 데이터베이스에서 데이터를 가져 와서 컬렉션보기를 다시로드합니다. 데이터가 맞는지 확인하여 문제가되지 않습니다.
나는func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
이 무슨 일 수있다 (여기서 화면에 상관없이, 버튼의 두 번째 필요 없음) 다음 메서드를 호출 할 때 항목을 인쇄하지 않고, 제 1 및 제 2의 클릭으로라고?
은'numOfRowAtIndexPath' 리턴 수 –
을 확인, 나는'numLessons' 변수에서 그것을 얻을. – CipherCit
비슷한 효과가 발생하여 _ [collectionView] reloadData _ _ 이전에 _ [collectionView.collectionViewLayout invalidateLayout] _ _ 작업했습니다. 필자의 경우 collectionview-viewcontroller (obj-c)는 신속한 viewcontroller의 child-viewcontroller입니다. – Apoc