视图

解决方案:
1、cell subview配置
// cell 添加背景view
cell.backView.tag = indexPath.row
// 热门城市 tag = -1
cell.titleLabel.tag = -1
2、CollectionView所在的TableviewCell中处理
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let view = super.hitTest(point, with: event)
guard let eView = view, eView.isDescendant(of: collectionView) else { return view }
if let tag = eView.tag, (-1 < tag && tag < sourceArr.count && !(eView is UICollectionView)) {
currentCity = sourceArr[tag]
collectionView.reloadData()
}
return collectionView
}

这篇博客探讨了在iOS开发中如何处理UICollectionView的视图配置,特别是为cell添加背景视图和设置标签。同时,讲解了如何在CollectionView所在的TableviewCell中实现hitTest方法,以便正确响应点击事件,并根据点击的tag更新当前城市和刷新数据。



5431

被折叠的 条评论
为什么被折叠?



