Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8686395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:50:14+00:00 2026-06-12T22:50:14+00:00

I have a collectionview that I am using to show thumbnails. I want it

  • 0

I have a collectionview that I am using to show thumbnails. I want it to be 4 columns across just like the photos app.

I got some example code (not much out there yet) and it’s confusing me with the math it’s doing.

I’m using an array (thumbs) that I build via NSXMLParser from XML coming back from a web service as the data source.

However, since the array doesn’t have ‘numberOfSections’ nor ‘numberOfItemsInSection'(it’s just a simple 2d array with photonames&locations) I am having trouble determining the math needed to adjust it to handle 4 across.

eg:If it’s the third row/2nd column, is that index 9(zero-base) in the array??
(since 2 full rows * 4 per row + 2(second column) = 10)?.. confused

Also note: the current code will only show an even # of pictures. So if there’s, say 3 pics in a particular album, only 2 will show.

Current Code:

`#pragma mark - UICollectionViewDataSource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    // Return the number of sections.
    return [thumbs count] / 2;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoCollCell" forIndexPath:indexPath];
    //get current photo from collection
    PhotoCollection *currentPhoto = [thumbs objectAtIndex:(indexPath.section*2 + indexPath.row)];

    //Show in PhotoName Cell
    cell.photoName.text = currentPhoto.PhotoName;

    //show thumb via:SDWebImage
    [cell.photoView setImageWithURL:[NSURL URLWithString:currentPhoto.PhotoThumbnailAbsoluteLocation] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

    //regular (wasn't working by default)
    //cell.photoView.image = [UIImage imageNamed:currentPhoto.PhotoThumbnailAbsoluteLocation];

    return cell;

}`
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:50:16+00:00Added an answer on June 12, 2026 at 10:50 pm

    The point of a collection view is that you don’t need to do these calculations. Use UICollectionViewFlowLayout as your layout class, make the cells the appropriate size (so only 4 will fit on a row) and have a single section containing all your thumbnails. The flow layout will give you a grid by automatically adjusting the position of the cells to fill the rows up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a NSCollectionView that I populate using [collectionView setContent:data]; where data is a
I have a CollectionView using the standard FlowLayout class with horizontal scrolling and a
I have a view model that currently looks like below. The TCm type is
I have an Android app with a UI like this for viewing emails: I'm
I have a view that gets used in each of my CollectionView's items. I
Both ArrayController and CollectionView have same functionality to render 'content' array using template, except
I have a datagrid that I want to filter based on a value selected
Using Ember.CollectionView I want to access and manipulate the DOM element which is being
I have a window that contains a grid with two columns. the first column
I have a colorpicker that I want to have his colors loaded from an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.