2016-08-08 38 views
3

我建立消息應用程序與流星 - 的iOS,一切都會很好,但我試圖使負載更多的功能,但我不能維護/保存滾動視圖的位置(當我滾動到頂部我要裝入多個項目,但保持在相同的位置滾動視圖插入前)UICollectionView加載頂部的項目 - 加載更多的選項

我的代碼:

func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) { 



    if type == NSFetchedResultsChangeType.Insert { 

     self.blockOperations.append(
      NSBlockOperation(block: { [weak self] in 
       if let this = self { 

        this.collectionView!.insertItemsAtIndexPaths([newIndexPath!]) 

       } 
       }) 
     ) 
    } 
    else if type == NSFetchedResultsChangeType.Update { 
     self.blockOperations.append(
      NSBlockOperation(block: { [weak self] in 
       if let this = self { 


        this.collectionView!.reloadItemsAtIndexPaths([indexPath!]) 
       } 
       }) 
     ) 
    } 
    else if type == NSFetchedResultsChangeType.Move { 

     self.blockOperations.append(
      NSBlockOperation(block: { [weak self] in 
       if let this = self { 
        this.collectionView!.moveItemAtIndexPath(indexPath!, toIndexPath: newIndexPath!) 
       } 
       }) 
     ) 
    } 
    else if type == NSFetchedResultsChangeType.Delete { 

     self.blockOperations.append(
      NSBlockOperation(block: { [weak self] in 
       if let this = self { 
        this.collectionView!.deleteItemsAtIndexPaths([indexPath!]) 
       } 
       }) 
     ) 
    } 



} 

self.collectionView!.performBatchUpdates({() -> Void in 
      for operation: NSBlockOperation in self.blockOperations { 
       operation.start() 
      } 
      }, completion: { (finished) -> Void in 
       self.blockOperations.removeAll(keepCapacity: false) 


     }) 

我使用的核心數據和流星IOS。那些人知道我能做什麼?我也試過how to set UITableView's scroll position to previous location when click "load earlier items" button任何其他許多沒有成功:(

非常感謝您!

+0

你好,你解決了嗎? –

回答

0

是的,我做了,如果範圍20-50以contentOffset.y之間的語句,如果之間的那些值,以便調用loadMore( )一次。

製作布爾值,以節省isLoadFinish,等到小區更新。如果你不這樣做的loadMore()將調用多個時間。

對於UX的經驗,你必須保存舊contentOffset .y在調用loadMore()並在加載後重置它之前。

我現在需要改進很多,簡單的黑客攻擊。

祝你好運。

+0

給我們一些可解釋的代碼,我已經嘗試,因爲你同樣但不工作 –