2016-11-03 10 views
0

私は多くのセルを管理するUICollectionViewを持っています。セルを削除すると、refreshControlでセルが消えてしまいます。しかし、なぜreloadDataが動作しないのか分かりません。誰かが私に事前に感謝を助けることができれば。私の見解のdidLoadで refreshControlでreloadData()が機能しません

self.collectionView!.alwaysBounceVertical = true 
let refresher = UIRefreshControl() 
refresher.tintColor = MyColor.Color 
refresher.addTarget(self, action: #selector(PublicListController.refreshStream), forControlEvents: .ValueChanged) 
refreshControl = refresher 
collectionView!.addSubview(refreshControl!) 

collectionView.dataSource = self 
self.populateDataBest() 

私は単に機能:

func populateDataBest() { 
    self.videosService.get(true, completionHandler: { 
     videosBest, error in 
     dispatch_async(dispatch_get_main_queue(), { 
      if error != nil { 
       if error!.code == -999 { 
        return 
       } 
       self.displayError(informations.LocalizedConnectionError) 
       return 
      } 
       self.bestClip = videosBest 
       for (indexBest, _) in (self.bestClip?.enumerate())! { 
        let videoBest:Clip = self.bestClip![indexBest] 
        self.pictureArrayVideo.addObject(["clip": videoBest, "group": "BEST"]) 
       } 
       self.dataSource.updateData(self.pictureArrayVideo) 
       self.collectionView.reloadData() 
     }) 
    }) 
} 

との最初のリロード作業:

func refreshStream() { 
    collectionView?.reloadData() 
    refreshControl?.endRefreshing() 
} 

私は、メソッドのpopulateDataBestと私のCollectionViewを完了します私のメソッドの終わりpopulateDataBest ..

EDIT:

私は私の要素(私はちょっと私のテストのためのremoveメソッドにパラメータに0を置く)

func refreshStream() { 
     dispatch_async(dispatch_get_main_queue(), { 
     self.remove(0) 
     self.collectionView.reloadData() 
    }) 
    self.refreshControl.endRefreshing() 
} 

func remove(i: Int) { 
    self.listForPager.removeAtIndex(i) 
    let indexPath: NSIndexPath = NSIndexPath(forRow: i, inSection: 0) 
    self.collectionView.performBatchUpdates({ 
     self.collectionView.deleteItemsAtIndexPaths(NSArray(object: indexPath) as! [NSIndexPath]) 
     }, completion: { 
      (finished: Bool) in 
      self.collectionView.reloadItemsAtIndexPaths(self.collectionView.indexPathsForVisibleItems()) 
    }) 
} 

を削除し、私は後にこのエラーを持っている機能を実装しよう

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (8) must be equal to the number of items contained in that section before the update (8), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).' 

誰かが理由を知っているとplzは私を助けることができますか?

Thxです。

+0

"swift IOS"をタイトルに追加する必要はありません。すでにこれらのタグがあります。 –

答えて

1

あなたのコレクションからあなたのコレクションに乗っているなら、その行が消えて最後にリロードするためのアイテムも削除する必要があります。

+0

これはサーバー上で要求を受け取る配列です。しかし、アプリケーションを切断して再接続すると、要素は消えます(配列に変更を加えることなく)。私は再接続を切断して再接続するのを避けて、refreshControlを使用します。私はテーブルの要素を取り除かなければならないのですか? – CizooDev

+0

はい。あなたはテーブルの要素を削除する必要があります! – breno

関連する問題