gpt4 book ai didi

ios - 仅限 iOS9 上的 UICollectionView NSInternalInconsistencyException 错误

转载 作者:搜寻专家 更新时间:2023-10-31 22:58:37 25 4
gpt4 key购买 nike

我在 iOS9 上得到这个,但在 iOS10 上一切正常:

Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.12/UICollectionView.m:1599

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView dataSource is not set' libc++abi.dylib: terminating with uncaught exception of type NSException

编辑:我的代码

//also have all dataSources in storyboard, this func just to be clear, called in viewDidLoad
func delegates() {
self.nearbyRestarauntsCollectionView.dataSource = self
self.topCollectionView.dataSource = self
self.restOfTheWeek.dataSource = self
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch collectionView {
case topCollectionView:
return dataForBestChoise.count
case nearbyRestarauntsCollectionView:
return dataForNearest.count
case restOfTheWeek:
return dataForTop.count
default:
return groupedSelection["\(selectionTypes[collectionView.tag])"]!.count
}
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
switch collectionView {
case topCollectionView:
return CGSize(width: UIScreen.main.bounds.width, height: 292)
case nearbyRestarauntsCollectionView:
return CGSize(width: 190, height: 196)
case restOfTheWeek:
return CGSize(width: UIScreen.main.bounds.width, height: 230)
default:
return CGSize(width: 150, height: 180)
}
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch collectionView {
case topCollectionView:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "topCollectionViewCell", for: indexPath) as! MainTopCollectionViewCell
if UIScreen.main.bounds.width < 375 {
cell.ratingCenterOutlet.constant = 5
} else {
cell.ratingCenterOutlet.constant = 20
}
cell.setupCell(data: dataForBestChoise[indexPath.row])
return cell

case nearbyRestarauntsCollectionView:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "nearbyRestarauntsCell", for: indexPath) as! NearbyRestarauntsCollectionViewCell
cell.setupCell(data: dataForNearest[indexPath.row])
return cell

case restOfTheWeek:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "restsOfTheWeek", for: indexPath) as! RestsOfTheWeekCollectionViewCell
cell.setupCell(data: dataForTop[indexPath.row])
if defaults.bool(forKey: "isLogged") {
if dataForTop[indexPath.row].isFavourited {
cell.isFavourited.isHidden = false
cell.isFavourited.image = UIImage(named: "isFavouritedTrue")
} else {
cell.isFavourited.isHidden = false
cell.isFavourited.image = UIImage(named: "selectionIsNotFav")
}
} else {
cell.isFavourited.isHidden = true
}

cell.isFavourited.isUserInteractionEnabled = true
let imageTap = UITapGestureRecognizer(target: self, action: #selector(self.addRestToFavourites))
imageTap.cancelsTouchesInView = true
imageTap.numberOfTapsRequired = 1
cell.isFavourited.addGestureRecognizer(imageTap)
cell.isFavourited.tag = indexPath.row
return cell


default:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "bottomSelectionCVCell", for: indexPath) as! BottomSelectionCollectionViewCell
cell.setupSelection(tag: collectionView.tag, row: indexPath.row, selection: (groupedSelection["\(selectionTypes[collectionView.tag])"]?[indexPath.row])!)

if defaults.bool(forKey: "isLogged") == true {
if cell.isFavourited == true {
cell.favImage.isHidden = false
cell.favImage.image = UIImage(named: "isFavouritedTrue")
} else {
cell.favImage.isHidden = false
cell.favImage.image = UIImage(named: "selectionIsNotFav")
}
} else {
cell.favImage.isHidden = true
}

cell.favImage.isUserInteractionEnabled = true
let imageTap = UITapGestureRecognizer(target: self, action: #selector(self.addSelectionToFavourites))
imageTap.cancelsTouchesInView = true
imageTap.numberOfTapsRequired = 1
cell.favImage.addGestureRecognizer(imageTap)
return cell
}
}

一个 Collection View 在 tableView 中:

func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.selectionTypes.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "bottomSelectionCell", for: indexPath) as! BottomSelectionsTableViewCell
cell.selectionGroupName.text = self.selectionTypes[indexPath.row].uppercased()
cell.selectionGroupName.addCharactersSpacing(1.95, text: cell.selectionGroupName.text!)
cell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.row)
return cell
}


func setCollectionViewDataSourceDelegate <D: UICollectionViewDataSource & UICollectionViewDelegate> (_ dataSourceDelegate: D, forRow row: Int) {
collectionView.delegate = dataSourceDelegate
collectionView.dataSource = dataSourceDelegate
collectionView.tag = row
collectionView.reloadData()
}

编辑2:我重建了整个 UIViewController(删除了旧的并制作了新的),但仍然出现此错误。

最佳答案

好的,所以我有方法

func setupCell() {
self.layoutIfNeeded()
if self.gradientView.layer.sublayers == nil {
self.gradientView.drawGradient(colors: [whiteColor.cgColor, colorWithAlpha(whiteColor, alpha: 0.5).cgColor], locations: [0, 1])
}
self.mapView.isMyLocationEnabled = false
self.mapView.settings.myLocationButton = false
self.locationManager.delegate = self
self.nearyLabel.addCharactersSpacing(1.94, text: "Рядом")
if CLLocationManager.authorizationStatus() == .authorizedAlways || CLLocationManager.authorizationStatus() == .authorizedWhenInUse {
self.locationManager.startUpdatingLocation()
} else {
let coordinateCenter = CLLocationCoordinate2DMake(37.606384, 55.765191)
self.mapView.camera = GMSCameraPosition(target: coordinateCenter, zoom: 14, bearing: 0, viewingAngle: 0)
}
}

问题是 self.layoutIfNeeded(),我删除了这一行,一切正常。我不知道发生了什么,因为正如我所说,iOS10 很好。

关于ios - 仅限 iOS9 上的 UICollectionView NSInternalInconsistencyException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40741899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com