Reputation: 275
I had an issue which is I can't scroll to my last item in a horizontal UICollectionView
. How can I fix this problem? Below is a link to my video and my project file because it's hard to explain. Hope someone can help me with this problem.
Thank you in advance.
https://drive.google.com/file/d/0BwvEaCrhg6dTbkdTRUYwTjhNN2c/view?usp=sharing
Here is my code for UIViewcontroller that have UICollectionView :
@synthesize dummyArrayImage,dummyArrayLabel,dummyDictionary,dummyArrayDescriptionLabel;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
dummyArrayImage = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
dummyArrayLabel = [[NSArray alloc] initWithObjects:@"RM 3.00",@"RM 10.00",@"RM 5.90",@"RM1.20",@"RM 8.10", nil];
dummyArrayDescriptionLabel = [[NSArray alloc] initWithObjects:@"Tesco Choco Milk",@"Tesco Sardin",@"Ayam Goreng",@"Ikan Pari",@"Itik", nil];
dummyDictionary = @{@"image":dummyArrayImage, @"label":dummyArrayLabel, @"description":dummyArrayDescriptionLabel};
NSLog(@"dummy dictionary : %@", dummyDictionary);
NSLog(@"dummy array : %@", dummyArrayImage);
NSLog(@"dummy array count : %d", (int)dummyArrayImage.count);
NSLog(@"dummy dictionary count : %d", (int)dummyDictionary.count);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UICollectionView
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return dummyArrayImage.count;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
TezCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell identifier" forIndexPath:indexPath];
UIImage *contentImage = [UIImage imageNamed:dummyArrayImage[indexPath.row]];
cell.contentImageView.image = contentImage;
cell.titleLabel.text = dummyArrayDescriptionLabel[indexPath.row];
cell.descriptionLabel.text = dummyArrayLabel[indexPath.row];
return cell;
}
Upvotes: 4
Views: 3055
Reputation: 314
add Top, Bottom Trailing and Leading Constraint in UICollectionView has solved the problem for me!
Upvotes: 1
Reputation: 275
I figured out by my own. This problem happened because I'm using autolayout. I tried to play with autolayout constraint and suddenly it's working as expected. Thank you for all those whose answered my question. You guys rock. Cheers.
Upvotes: 2