2015-10-23 82 views
2

我有一個問題,這是我不能滾動到我的最後一個項目在一個水平UICollectionView。我該如何解決這個問題?下面是我的視頻和我的項目文件的鏈接,因爲很難解釋。希望有人能幫助我解決這個問題。UICollectionView水平滾動不滾動,直到最後項目

預先感謝您。

https://drive.google.com/file/d/0BwvEaCrhg6dTbkdTRUYwTjhNN2c/view?usp=sharing

https://youtu.be/8WVyrUl4qfQ

這裏是我的UIViewController的代碼,有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; 

} 
+0

請張貼一些代碼。 – anhtu

+0

這是因爲UIEdgeInsets,或部分插圖的,也許你有錯誤的配置 – ogres

+0

添加一些代碼在這裏,可能是你的集合視圖內容視圖問題,請複製粘貼一些代碼在這裏,,, – ilesh

回答

2

我想通了,我自己的。發生此問題是因爲我使用了自動佈局。我試圖玩自動佈局約束,並突然它按預期工作。感謝所有回答我的問題的人。你們好棒。乾杯。

+0

絕對,你的約束沒有設置正確,所以收集視圖不顯示最後一個單元格。 – ilesh

0

在UICollectionView中添加頂部,底部尾部和前導約束解決了我的問題!