插入新数据时UICollectionview滚动会挂起,加载时会随机崩溃

时间:2016-06-15 10:25:52

标签: ios swift uiscrollview uicollectionview uicollectionviewcell

我正在尝试通过UICollectonView将新项目添加到insertItemsAtIndexPaths,但我会在abpve场景中随机崩溃

  1. 如果执行了任何用户互动
  2. 插入时
  3. Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (22) must be equal to the number of items contained in that section before the update (10), plus or minus the number of items inserted or deleted from that section (10 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).

    当我插入时,UICollectionview`卷轴也会挂起,任何人都会提出一些解决方法。谢谢

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of items
    
        print("section called")
        if(activityTableView.onlineFeedsData.length != 0){
            if(customSC.selectedSegmentIndex == 0){
                activityTableView.selectedType = "latest"
                return activityTableView.postArr.count
            }else{
                activityTableView.selectedType = "popular"
                return activityTableView.postPopularArr.count
            }
    
    
        }
    
    
        return 0
    
    
    }
    

    插入功能

    func insertFeeds(data : NSData , type : String){
      activityTableView.performBatchUpdates({
    
                            print("closure")
    
                            self.activityTableView.insertItemsAtIndexPaths(indexPaths)
                            self.activityTableView.postArr.addObjectsFromArray(resultArr as [AnyObject])
                            self.activityTableView.onlineFeedsData = NSData(data: try! NSJSONSerialization.dataWithJSONObject(self.activityTableView.postArr, options: [])).mutableCopy() as! NSMutableData // new
    
                            print("closure end")
    
                            }, completion: { (bool) in
    
                                print("completion")
                        })
    
     }
    

0 个答案:

没有答案