2016-08-08 41 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

给我们一些可解释的代码,我已经尝试,因为你同样但不工作 –