Nim*_*od7 80 ios uicollectionview
在我的项目中,我使用UICollectionView来显示图标网格.
用户可以通过单击分段控件来更改排序,该分段控件使用不同的NSSortDescriptor调用从核心数据中获取.
数据量始终相同,只是以不同的部分/行结束:
- (IBAction)sortSegmentedControlChanged:(id)sender {
_fetchedResultsController = nil;
_fetchedResultsController = [self newFetchResultsControllerForSort];
NSError *error;
if (![self.fetchedResultsController performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
[self.collectionView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
问题是reloadData没有为更改设置动画,UICollectionView只是弹出新数据.
我应该跟踪更改前后单元格中的哪个indexPath,并使用[self.collectionView moveItemAtIndexPath:toIndexPath:]来执行更改动画,还是有更好的方法?
我没有太多进入子类化collectionViews所以任何帮助将是伟大的...
比尔,谢谢.
pau*_*kow 143
结束语-reloadData
中-performBatchUpdates:
似乎没有引起一个截面集合视图动画.
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadData];
} completion:nil];
Run Code Online (Sandbox Code Playgroud)
但是,此代码有效:
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:nil];
Run Code Online (Sandbox Code Playgroud)
Str*_*pes 67
reloadData不会设置动画,也不会在放入UIView动画块时可靠地执行此操作.它想要在UICollecitonView performBatchUpdates块中,所以尝试更像:
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:^(BOOL finished) {
// do something on completion
}];
Run Code Online (Sandbox Code Playgroud)
Yar*_*sim 65
这就是我为动画重新加载ALL SECTIONS所做的工作:
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.collectionView.numberOfSections)]];
Run Code Online (Sandbox Code Playgroud)
斯威夫特3
let range = Range(uncheckedBounds: (0, collectionView.numberOfSections))
let indexSet = IndexSet(integersIn: range)
collectionView.reloadSections(indexSet)
Run Code Online (Sandbox Code Playgroud)
对于Swift用户,如果您的collectionview仅包含一个部分:
self.collectionView.performBatchUpdates({
let indexSet = IndexSet(integersIn: 0...0)
self.collectionView.reloadSections(indexSet)
}, completion: nil)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
75825 次 |
最近记录: |