【问题标题】:UICollectionView Horizontal Scrolling Does Not Scroll Until Last ItemUICollectionView 水平滚动不会滚动到最后一项
【发布时间】:2016-01-22 18:53:28
【问题描述】:

我遇到了一个问题,我无法滚动到水平 UICollectionView 中的最后一项。我该如何解决这个问题?下面是我的视频和我的项目文件的链接,因为它很难解释。希望有人可以帮助我解决这个问题。

提前谢谢你。

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

https://youtu.be/8WVyrUl4qfQ

这是我的具有 UICollectionView 的 UIViewcontroller 代码:

@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;

}

【问题讨论】:

  • 请贴一些代码。
  • 这是因为 UIEdgeInsets 或者 section insets ,可能你的配置错误
  • 在此处添加一些代码,可能是您的收藏视图内容视图问题,请在此处粘贴一些代码,,,
  • @Mohamad Afiq 在情节提要中选择您的视图控制器并取消选中“调整滚动视图插图”选项并告诉我您是否仍然遇到同样的问题。
  • @bhavinramani 我尝试了你的建议,但这并没有解决我的问题。

标签: ios objective-c uicollectionview horizontal-scrolling


【解决方案1】:

我自己想出来的。发生此问题是因为我正在使用自动布局。我尝试使用自动布局约束,突然它按预期工作。感谢所有回答我问题的人。你们好棒。干杯。

【讨论】:

  • 绝对,您的约束设置不正确,因此集合视图不显示最后一个单元格。
【解决方案2】:

在 UICollectionView 中添加顶部、底部尾随和前导约束已经为我解决了这个问题!

【讨论】:

  • 谢谢你同样的问题,因为我使用自动布局
猜你喜欢
  • 1970-01-01
  • 2016-09-17
  • 1970-01-01
  • 2013-10-18
  • 1970-01-01
  • 2014-11-15
  • 2022-01-19
相关资源
最近更新 更多