When I start the application, the view looks like this.
The CollectionView basically overflows from the bottom, meaning that part of it can not be seen even if I scroll down.
However, as soon as I rotate the device to left and then back to right (from portrait to landscape and back to portrait) it goes to what I want it to look like.
Is there a way to refresh the view in viewDidLoad so that it would look like it looks after rotating twice?
CollectionViewController.m #import "CollectionViewController.h"
@interface CollectionViewController () {
NSArray * listImages;
}
@end
@implementation CollectionViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.jpg"]]];
// Do any additional setup after loading the view.
listImages = [NSArray arrayWithObjects:@"7513-kirjatkuivumassa.jpg", @"kuppi.jpg", @"kuva1.jpg", @"juna-042.jpg", @"rautio-valamonruusut-helleaamuna-maalaus.jpg", @"pysähtynyt1.jpg", @"Screen-Shot-2013-02-20-at-21.07.38.jpg", @"sateenkaari.jpg", @"Screen-Shot-2013-02-21-at-17.04.22.jpg", @"moninaiset-e1391026376696.jpg", @"Tomperi+Metsä20111.jpg", @"3-shinot.jpg", @"Ulpukat.jpg", @"janne-e1391025808211.jpg", @"martikainen-240x240.jpg", @"takala-240x240.jpg", @"paanukallokaarme1.jpg", @"käsityök-240x240.jpg", @"kuvis-004.jpg", @"Se-on-hieno-2012-tammi-105x28x223.jpg", nil];
}
- (void)viewDidLayoutSubviews
{
[self.collectionView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [listImages count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
UIImageView *listImageView = (UIImageView *)[cell viewWithTag:100];
listImageView.image = [UIImage imageNamed:[listImages objectAtIndex:indexPath.row]];
return cell;
}
CollectionViewController.h
#import <UIKit/UIKit.h>
@interface CollectionViewController : UIViewController
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@end