UICollectionView is not scrolling to position

175 views Asked by At

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

There are 1 answers

1
Bannings On BEST ANSWER

There are only two small problems:

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

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

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]];
}