[英]UICollectionView is not scrolling to position
I have a UICollectionView
in a static UITableView
. 我在静态
UITableView
有一个UICollectionView
。 I'm trying to make the collectionView
scroll to an indexPath
in viewDidLoad
. 我试图使
collectionView
滚动到viewDidLoad
的indexPath
。 It's not scrolling to position on startup, when I select an indexPath
it scrolls to that position. 它没有滚动到启动位置,当我选择一个
indexPath
它滚动到该位置。 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
所以这里是: 有问题的项目
There are only two small problems: 只有两个小问题:
1.The selectedDate
does not match with your dates
array. 1.
selectedDate
不匹配您的dates
排列。 Compare the two date in the following image: 比较下图中的两个日期:
2.You should update UI in viewDidAppear
as @Omar Al-Shammary said. 2.您应该按照@Omar Al-Shammary的说明更新
viewDidAppear
UI。
The Solution: 解决方案:
- (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]];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.