2016-03-29 3 views
0

私はactivityCellを作成しようとしています。ユーザーがボタンに到達すると、アクティビティインジケータ付きのセルが表示されます。これは正常に動作するようですが、moreDataAvailablefalseの場合、このセルは削除されます。しかし、私は次のエラーが続いている?アクティビティセルをさらに読み込みます。CollectionViewCell

'NSInternalInconsistencyException', reason: 'attempt to delete item 0 from section 1 which only contains 0 items before the update'

numberOfItemsInSection

override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int 
{ 

    if section == 0 { 
     return organizationArray.count 
    } else { 
     if self.moreDataAvailable == true { 
      return 1 
     } else { 
      return 0 
     } 
    } 

} 

隠すコレクションセル

func hideCollectionViewFooter() { 



    self.collectionView!.deleteItemsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 1)]) 
} 

numberOfSectionsInCollectionView

override func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) { 

     if !loadingData && indexPath.item == organizationArray.count - 1 && self.moreDataAvailable { 

      self.loadingData = true 

      proposeAccess(false, success: { 
       self.loadingData = false 
      }) 

     } 
} 

更新組織に到達し、より多くのデータが

利用可能であるかどうかを確認するとき
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { 

    return 2 
} 

cellForItemAtIndexPath

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 


    if indexPath.section == 0 { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("OrganizationCell", forIndexPath: indexPath) as! OrganizationCollectionViewCell 


     cell.customerLabel?.text = organizationArray[indexPath.item].name.uppercaseString 

     cache.fetch(key: organizationArray[indexPath.item].coverPhoto).onSuccess { data in 
      cell.customerImageView?.image = UIImage(data: data) 
     } 
     return cell 
    } else { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ActivityCell", forIndexPath: indexPath) as UICollectionViewCell 
     return cell 

    } 


} 

ロード詳細

+0

セクションの定義数はどこですか? activityCellをセクション0の最後のアイテムとして追加するのではなく、新しいセクションの新しいアイテムとして追加しているようです。 – dirkgroten

+0

申し訳ありません、私はそれを追加して、セルのmetodを非表示にしました –

答えて

0

このエラーは、現在のテーブルビューの状態では存在しなかったセルを削除しようとしていることを意味します。 UpdateOrganizationsのリクエストが完了する前に、おそらくmoreDataAvailableがすでに偽であったでしょう。

アクティビティインジケータを表示するには、表のフッタービューを使用することをお勧めします。また、データがロードされた後、ロードされたアイテムの数を表示することができます。

+0

私のコードでどこが間違っているのかを見てください: 'updateOrganizations'はviewDidLoadで呼び出され、' reloadData'は 'organizationArray'のdidSetにあります。どのようにコレクションビューでtableViewFooterを使用できますか? –

+0

@PeterPik申し訳ありませんが、コレクションビューであることに気付きませんでした。例えば。コレクションビュー:viewForSupplementaryElementOfKind:atIndexPath: ' 'updateOrganizations'を呼び出す前に' moreDataAvailable = true'を設定しましたか? –

+0

はい、それはtrueに設定されています –

関連する問題