如何检测滚动到UICollectionView中的新节?

mag*_*gix 6 objective-c nsindexpath ios uicollectionview uicollectionreusableview

我正在实现一个无限滚动的日历.我的问题是我想将当前月份设置为导航栏中的标题,并且它应该在滚动时更新 - 一旦您传递了标题标题视图,标题应该在导航栏中更新.

一种可能的解决方案是在被调用的方法中设置视图标题,- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath这样,当我计算新的节标题时,它也会更新标题.这个问题是当新部分位于页面底部时标题会发生变化.

当前将节标题显示为标题,不是最佳标题

有没有办法知道UICollectionView用户滚动到它后的"当前部分" ?或者您能想出一种改进现有解决方案的方法吗?

为了帮助这篇文章的读者,我在这个GitHub回购中发布了我自己的这个问题的示例代码.

KDe*_*kar 0

更改方法中的以下行viewForSupplementaryElementOfKind

self.title = [df stringFromDate:[self dateForFirstDayInSection:indexPath.section]];
Run Code Online (Sandbox Code Playgroud)

对此:

    if(![[self dateForFirstDayInSection:indexPath.section-1] isKindOfClass:[NSNull class]]){
        self.title = [df stringFromDate:[self dateForFirstDayInSection:indexPath.section-1]];
}
Run Code Online (Sandbox Code Playgroud)

希望它能帮助你。