How To Create A Gridview With ‘UICollectionView’ In IOS6 & Above

How To Create A Gridview With ‘UICollectionView’ In IOS6 & Above
Social sharing
Contents

What Is ‘UICollectionView’?

‘UICollectionView’ is a class introduced in iOS 6 SDK. It helps developers in creating grid view to handle ordered collection of data items using customizable layouts. ‘Collection view’, available in this class is like ‘UItableview’ which supports multiple column layouts.

Getting Started:

Create new ‘.h‘ and ‘.m‘ files to display the images.

In ‘ShowImagesViewController.h

#import <UIKit/UIKit.h>
@interface ShowImagesViewController :UICollectionViewController
{
NSArray *allImages;
}
@property (nonatomic, retain) NSArray *allImages;
@end

In ‘ShowImagesViewController.m

#import "ShowImagesViewController.h"
@implementation ShowImagesViewController
@synthesize allImages;
- (void)viewDidLoad
{
[superviewDidLoad];
allImages = [NSArrayarrayWithObjects:@"pizza.jpeg",
@"sides_img.png", @"sandwich_img.png", @"pizza_img.png",
@"pasta_img.png", @"drinks_img.png", @"pizza.jpeg",
@"sides_img.png", @"sandwich_img.png", @"pizza_img.png",
@"pasta_img.png", @"drinks_img.png", nil];
}
 
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (NSInteger)collectionView:(UICollectionView *)collectionViewnumberOfItemsInSection:(NSInteger)section
{
returnrecipeImages.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionViewcellForItemAtIndexPath:(NSIndexPath *)indexPath
{
staticNSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView
dequeueReusableCellWithReuseIdentifier:identifier
forIndexPath:indexPath];
 
UIImageView *allImageView = (UIImageView *)[cell viewWithTag:100];
allImageView.image = [UIImageimageNamed:[allImagesobjectAtIndex:indexPath.row]];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionViewdidSelectItemAtIndexPath:(NSIndexPath *)indexPath{
}
@end

Example of Grid layout using ‘UICollectionViewController

uicollectionview

Conclusion:

‘UICollectionViewController’ creates ‘Grid’/’Tile’ layout much faster and offers intuitive user interface in iOS 6 devices.

Your recently viewed posts:

Jayadev Das - Post Author

Do what you do best in – that’s what I’ve always believed in and that’s what I preach. Over the past 25+ years (yup that’s my expertise ‘n’ experience in the Information Technology domain), I’ve been consulting to small, medium and large companies ‘About Web Technologies, Mobile Future as well as on the good-and-bad of tech. Blogger, International Business Advisor, Web Technology Expert, Sales Guru, Startup Mentor, Insurance Sales Portal Expert & a Tennis Player. And top of all – a complete family man!

    Contact Us

    We’d love to help & work with you




    When do you want to start ?


    Enter your email address to stay up to date with the latest news.
    Holler Box

    Orange Exit pop up

    Subscribe for the latest
    trends in web and
    mobile app development
    Holler Box

    Exit pop up

    Sad to see you leaving early...

    From "Aha" to "Oh shit" we are sharing everything on our journey.
    Enter your email address to stay up to date with the latest news.
    Holler Box