2016-11-03 2 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 ..의 끝

,210

편집 : 내 요소

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()) 
    }) 
} 

(난 그냥 그 순간 내 시험을 위해 제거 방법에 대한 매개 변수에 0을 넣어) 제거 기능을 구현하려고

그리고이 오류 후이

*** 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

"스위프트 IOS"를 제목에 추가 할 필요가 없습니다. 이미이 태그가 있습니다. –

답변

1

배열에서 콜렉션을 타는 경우 줄을 사라지게하고 마지막으로 다시로드하기 위해 항목을 삭제해야합니다.

+0

서버에서 요청을 가져 오는 배열입니다. 그러나 연결을 끊고 응용 프로그램을 다시 연결하면 요소가 사라집니다 (배열을 수정하지 않고). 연결을 끊었다가 다시 연결하여 다시로드하지 않으므로 refreshControl을 사용합니다. 그때 테이블의 요소를 제거해야합니까? – CizooDev

+0

예. 당신은 테이블의 요소를 제거해야합니다! – breno

관련 문제