我使用meteor-iOS构建消息应用程序,一切都很好,但我正在尝试加载更多功能但我无法维护/保存滚动视图的位置(当我滚动到顶部我想要加载更多项目,但保持滚动视图与插入前的位置相同)
我的代码:
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)
})
我正在使用核心数据和meteor-ios。有谁知道我能做什么?我还试过how to set UITableView's scroll position to previous location when click "load earlier items" button任何其他许多没有成功:(
非常感谢!!
答案 0 :(得分:0)
是的,我在范围20-50到contentOffset.y之间做了if语句。如果它在这些值之间,那么调用loadMore()一次。
使bool值保存isLoadFinish并等到单元格更新。如果您不这样做,loadMore()将多次调用。
对于UX体验,您必须在调用loadMore()之前保存旧的contentOffset.y,并在加载后重置它。
我现在需要改进它,简单的黑客攻击。
祝你好运。