【发布时间】:2018-05-24 12:53:14
【问题描述】:
我目前正在开发一个 UIViewController,顶部有一个水平 collectionView,接下来几个月的星期几(如日历),在它下面我有一个 tableView,下一个事件发生在用户位置附近. 当用户向下滚动表格视图时,它会获取顶部单元格事件日期并将 collectionView 滚动到那一天。我正在使用以下代码:
在 tableView 的 cellForRowAt 上:
datePicker.selectItem(at: selectedIndexPath, animated: true, scrollPosition:UICollectionViewScrollPosition.centeredHorizontally)
在 collectionView 的 cellForItemAt 上:
if cell.isSelected {
cell.selectedCircle.layer.cornerRadius = 15
cell.selectedCircle.backgroundColor = UIColor(red:1, green:0.08, blue:0.35, alpha:1)
cell.weekDayLabel.alpha = 1
selectedMonth.text = dateToday.3.firstUppercased
} else {
cell.selectedCircle.backgroundColor = UIColor(red:1, green:0.08, blue:0.35, alpha:0)
cell.weekDayLabel.alpha = 0.4
}
当下一个要选择的 collectionView IndexPath 与前一个相距甚远时,一切都可以正常工作。当它们相距大约 8 或低于 indexPaths 时,collectionView 滚动到正确的 indexPath 但不运行 isSelected 代码。
有什么想法吗?感谢您的时间。
【问题讨论】:
标签: ios swift uicollectionview