Question

I'v never used UITableViewControllers or UICollectionViewControllers, because you can have the same functionality by using UIViewController with its root UIView, then adding UITableView in xib or storyboard and assigning its delegate and datasource. And I also was able to put activity indicator inside the center of root UIView.

Now the things get a little bit complicated when using UICollectionViewController where its root view is UICollectionView. I need to update some code of other guys and they put activity indicator inside UICollectionView (in storyboard). The problem is this activity indicator gets hidden when cells are reused because activity indicator view is the most bottom one. I was unable to change visibility priority storyboard and also this code in view didLoad is not working:

[self.itemsCollectionView bringSubviewToFront:self.activityIndicator];

Because labels, images and etc. views of collection view cell are placed later, during collectionView:cellForItemAtIndexPath:. I could try to call bringSubviewToFront: in collectionView:cellForItemAtIndexPath: but that would be a wrong decision. Any ideas how to achieve this when using UITableViewControllers or UICollectionViewControllers?

IMHO the only reason to use UITableViewControllers or UICollectionViewControllers is because static cells are not shown storyboards when designing layout.

UPDATE It appears iOS wraps UICollectionView inside UICollectionViewControllerWrapperView. Tried to add activity to this wrapper view in viewWillAppear:

[self.itemsCollectionView.superview addSubview:self.activityIndicator];

But with no luck - activity indicator is still is below the cells.

Was it helpful?

Solution

I'v ended in refactoring existing UICollectionViewController in storyboards: I'v opened storyboard xml file with TextEdit, searched for the screen and changed its type from collectionViewController to viewController because was unable to find another way how to change the type of controller, though I hope there will appear some more elegant way for that in the nearest future. Then, I'v wrapped collectionView inside root view and placed activityIndicator inside this view. It's proven classical approach that works like a charm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top