Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you already have a collection view that does what you want just turn on paging. <code>self.collectionView.pagingEnabled = YES</code> You can also enable paging in IB by checking the paging box in the attributes inspector. Using a <code>UICollectionView</code> gives you the added benefit of reusable cells. </p> <h2>Edit</h2> <p>You could still use UICollectionView. Create an UICollectionViewCell subclass that contains your detail view. Then when you want to launch directly to a particular image you can use <code>- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated</code> If you're loading a ton of images in this view the scrollview method will load all of your images at once rather than on demand like they would in a collectionview scenario. You can always work around that in a scrollview but all that work's been done for you in UICollectionView.</p> <h2>Edit2</h2> <p>I started this in a comment but it was getting big...</p> <p>In your view controller subclass you will need to register either your class or a nib that you created to lay out that cell. I prefer the nib so I can lay everything out in Interface Builder. If you go the nib route you will create an empty xib and drag a UICollectionViewCell out of the object library in the bottom right. Then select that cell and make sure the Class is set to the custom subclass you've created.</p> <p>Now in your view controller subclass you'll call <code>– registerNib:forCellWithReuseIdentifier:</code> in the viewDidLoad method like this:</p> <pre><code> [self.collectionView registerNib:[UINib nibWithNibName:@"WhateverYouNamedYourNib" bundle:nil] forCellWithReuseIdentifier:@"cell"]; </code></pre> <p>Your view controller will conform to the <code>UICollectionViewDataSource</code> protocol and you will implement this method:</p> <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CustomCellClass *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath //Setup the cell with image and whatever else return cell; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload