I have a full-screen UICollectionView
in my app. It scrolls horizontally and each cell fills the collection view's bounds. The collection view is managed by a UIViewController
.
Given that each "page" is reasonably complex, it makes sense for each page itself to be managed by an associated UIViewController
. iOS 5 has support for view controller containment, so that the child controllers should receive the appropriate lifecycle methods (e.g. viewWillAppear:
, etc) when views are attached and detached. How nicely would this play with view recycling?
Scrolling from page "1", to "2", a new view would be created (as both could be onscreen at the same time during the touch-down). Moving from page "2" to "3", the UICollectionView
could successfully dequeue the view for page "1", but what happens now? Would I forcefully insert the view into view controller three like so?
id cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ident" forIndexPath:indexPath];
UIViewController *child_controller = [self controllerAtIndexPath:indexPath];
[child_controller setView:cell];
// ... and so on
This feels wrong. However, I can't think of a correct way to reuse views correctly in this instance. Am I taking the wrong approach entirely?
UIPageViewController
with itstransitionStyle
set toUIPageViewControllerTransitionStyleScroll
? It's designed to host one child view controller per page. – Mortify