【发布时间】:2016-08-08 17:03:06
【问题描述】:
我用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 任何其他方法都没有成功:(
非常感谢!!
【问题讨论】:
-
嗨,你解决了吗?
标签: ios swift uicollectionview