Home > DeveloperSection > Forums > Displaying images in UICollectionViewCell from database in iOS
Steven Hill
Steven Hill

Total Post:10

Posted on    November-30-2015 12:40 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 488  View(s)
Rate this:

I am a beginner in iPhone app development, I want to display image in UICollectionViewCell from using database.
In our programming I am using code like this :

SqliteDB *images;
images = [SQliteDB alloc] init];
imgArray = [images OpenMyDatabase: @"SELECT images FROM exterior" :


So, my problem is how can I display those images?

Tarun Kumar

Total Post:210

Posted on    December-02-2015 10:51 PM

Use my code to display UIImage grid. and add uicollectionView in your xib file.

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
   return  1;

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
   return [imgArray count];

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
   static NSString *identifier = @"Cell";

   UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:

identifier forIndexPath:indexPath];

   UIImageView *imgView = (UIImageView *)[cell viewWithTag:100];
   imgView.image = [UIImage imageNamed:[imgArray objectAtIndex:indexPath.row]];

   return cell;

and, don't forget to set delegate in collection before using that code.
and also in your xib file add UIImageView to your collection view cell and set its tag value to 100.

Don't want to miss updates? Please click the below button!

Follow MindStick