UICollectionView 没有滚动到位置 [英] UICollectionView is not scrolling to position

查看:27
本文介绍了UICollectionView 没有滚动到位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在静态 UITableView 中有一个 UICollectionView.我试图让 collectionView 滚动到 viewDidLoad 中的 indexPath.它不会在启动时滚动到位置,当我选择 indexPath 时,它会滚动到该位置.我做了一个干净的项目,产生了这个问题.

I have a UICollectionView in a static UITableView. I'm trying to make the collectionView scroll to an indexPath in viewDidLoad. It's not scrolling to position on startup, when I select an indexPath it scrolls to that position. I made a clean project that produces the problem.

我认为最简单的方法是不要让您尝试重新创建问题,而是将其上传.所以这里是:有问题的项目

I thought the simplest way to do this was instead of making you to try and recreate the problem, I would just upload it. So here it is: Project with problem

推荐答案

只有两个小问题:

1.selectedDate 与您的 dates 数组不匹配.比较下图中的两个日期:

1.The selectedDate does not match with your dates array. Compare the two date in the following image:

2.您应该像@Omar Al-Shammary 所说的那样更新 viewDidAppear 中的 UI.

2.You should update UI in viewDidAppear as @Omar Al-Shammary said.

解决方案:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:[NSDate date]];
    [self setSelectedDate:[calendar dateFromComponents:components]];
}

这篇关于UICollectionView 没有滚动到位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆