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 8607617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:24:13+00:00 2026-06-12T03:24:13+00:00

I am using a UICollectionView programmatically. I’ve set its frame as follows: UICollectionView *collectionView

  • 0

I am using a UICollectionView programmatically.

I’ve set its frame as follows:

UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 3000) collectionViewLayout:flowLayout];

My UICollectionViewFlowLayout has a section inset set as:

flowLayout.sectionInset = UIEdgeInsetsMake(20.0, 20.0, 100.0, 20.0);

I also only have 1 section.

I’ve set the height to be 3,000 to see if the collection view would scroll but it doesn’t. I am setting it to that since the collection view doesn’t seem to scroll up or down when I insert new items.

UICollectionView is subclassed from a UIScrollView, which means I can keep resetting the scroll view content size. Would this work properly?

The only issue is that this would work if I know the sizes of all items including how many items are on each row.

If each item had a different size, how would I find out the size of each row? I would need that to add all row sizes and increase the content size height of self.collectionView.

EDIT

Even my suggestion above, resetting the content size, does not work properly! I tried the following when updating my collection view:

 int numberOfRows = self.dataArray.count / 3;
self.collectionView.contentSize = CGSizeMake(self.view.frame.size.width, (numberOfRows * 200) + 300);

This is very ugly though. This is because it assumes all my images are of size 200x200px, which fits 3 images per row (hence the division by 3).

Furthermore, even with the +300 that I have, the last row I can only see about 3/4 of it and not all of it. I have to scroll more and I will be able to see it but it goes back up again to 3/4. Its kind of like the scroll to refresh, where the view only moves if you drag it and when you leave it bumps back to where it was. Why is this happening? Is it just that Apple designed UICollectionView so poorly? This is a little ridiculous… UITableViews adjust their scroll according to their content automatically.

  • 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-12T03:24:15+00:00Added an answer on June 12, 2026 at 3:24 am

    In answering some of your other questions about UICollectionView, I created this demo project, and it scrolls just fine, so I don’t know what problem you’re having. The only thing I needed to do to make the last row wholly visible was to increase the size of the bottom inset to 90. I also added a completion method to the performBatchUpdates:completion: to automatically scroll so that the last added item is visible (notice that I add some extra items by using performSelector;withObject:afterDelay:). My images are 48×48, and I just set my collection view to the bounds of my controller’s view. Here is the code so you can compare it to what you have:

    @interface ViewController () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout> {
    NSMutableArray *newData;
    }
     @property (nonatomic, retain) UICollectionView *collectionView;
     @property (nonatomic, retain) NSMutableArray *results;
     @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        self.results = [NSMutableArray array];
        int i = 11;
        while (i<91) {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"New_PICT00%d.jpg",i]];
            [self.results addObject:image];
            i++;
        }
    
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        //flowLayout.scrollDirection =  UICollectionViewScrollDirectionHorizontal;
    
        self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
        self.collectionView.dataSource = self;
        self.collectionView.delegate = self;
        self.view.backgroundColor = [UIColor blackColor];
        [self.view addSubview:self.collectionView];
        [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
        //[self.collectionView registerClass:[RDCell class] forCellWithReuseIdentifier:@"myCell"];
        [self.collectionView reloadData];
    
        [self performSelector:@selector(addNewImages:) withObject:nil afterDelay:3];
    }
    
    -(void)addNewImages:(id)sender {
        newData = [NSMutableArray array];
        int i = 102;
        while (i<111) {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"New_PICT0%d.jpg",i]];
            [newData addObject:image];
            i++;
        }
        [self addNewCells];
    }
    
    -(void)addNewCells {
        NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];
        [self.collectionView performBatchUpdates:^{
            int resultsSize = [self.results count];
            [self.results addObjectsFromArray:newData];
            for (int i = resultsSize; i < resultsSize + newData.count; i++)
                [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
            [self.collectionView insertItemsAtIndexPaths:arrayWithIndexPaths];
        }
        completion: ^(BOOL finished){
            [self.collectionView scrollToItemAtIndexPath:arrayWithIndexPaths.lastObject atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:YES];
        }];
    }
    
    
    - (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
        return [self.results count];
    }
    
    - (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
        return 1;
    }
    
    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
        //cell.iv.image = [self.results objectAtIndex:indexPath.row];
        cell.backgroundColor = [UIColor colorWithPatternImage:[self.results objectAtIndex:indexPath.row]];
        return cell;
    }
    
    
    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
        UIImage *image = [self.results objectAtIndex:indexPath.row];
        return CGSizeMake(image.size.width, image.size.height);
    }
    
    - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
        return UIEdgeInsetsMake(10, 10, 90, 10);
    }
    
    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
        NSLog(@"Selected Image is Item %d",indexPath.row);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using UICollectionView to generate several thumbnails in a Master View. This works
I'm making a horizontal picker by using a UICollectionView . It's simple enough: A
My application is using Self-Tracking Entities & I get my data from a WCF
As titled. So I was successfully to put DataTable into my CollectionView with using:
Using PyGtk's IconView, I can set the icons to be reorderable by calling gtk.IconView.set_reorderable(True)
I am currently trying to implement the UITableView reordering behavior using UICollectionView. Let's call
I am trying to implement UICollectionView and show images. I am using SDWebimage which
I have a collectionview that I am using to show thumbnails. I want it
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain
Using a populated Table Type as the source for a TSQL-Merge. I want to

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.