2016-11-22 38 views
3

我得到這個在iOS9,但iOS10一切正常:UICollectionView NSInternalInconsistencyException錯誤只

斷言失敗 - [UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:], /buildroot的/圖書館/緩存/ com.apple.xbs /資源/的UIKit/UIKit的-3512.60.12/UICollectionView.m:1599

終止應用程序由於未捕獲的異常 'NSInternalInconsistencyException',理由是:「UICollectionView 數據源爲n OT集」的libC++ abi.dylib:與未捕獲 異常類型NSException

EDIT的終止:我的代碼

//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 
    } 
} 

一個集合視圖是內部的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() 
} 

EDIT2 : 我重建整個UIViewController(刪除舊的和新的),但仍然得到這個錯誤。

+0

在您的問題中添加第1599行的代碼 –

+0

NSInternalInconsistencyException在此處說您尚未設置數據源。 –

+0

也許UICollectionView dataSource沒有設置? – shallowThought

回答

1

Ooookay,所以我不得不方法

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沒問題。

相關問題