I have a UICollectionView that I want to reload right before it is shown. The number of items in the collection view's source may have changed so the reloading happens to add the new items or remove those that should no longer be there.
In my view controller I have:
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
this.source.UpdateAvailableItems();
this.CollectionView.ReloadSections(new NSIndexSet(0));
}
This does what I want except that if items are getting removed, the collection view appears and the user briefly sees those items disappear. The situation is similar for adding new items, but it's a little harder to see the new items getting added.
(ReloadData basically doesn't work, which is why I'm using ReloadSections. See: UICollectionView reloadData not functioning properly in iOS 7)
(I can't really reload the collection view every time the source's items change, because that is happening potentially a hundred times per second when it's not visible)
Does anyone know of a way I could have the collection view reloaded and rendered completely before it appears? Wrapping the ReloadSections call with UIView.PerformWithoutAnimation also does not help.
ANSWER: C# implementation of Tim Edward's solution:
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
this.source.UpdateAvailableItems();
UIView.PerformWithoutAnimation(() =>
{
this.CollectionView.PerformBatchUpdates(
() => this.CollectionView.ReloadSections(new NSIndexSet(0)),
null);
});
}