如何解决在单个 UICollectionView 中的 2 组数据之间进行选择
我需要一个 UICollection 视图来在选择时显示 2 组数据中的 1 组。我想使用分段控件,但也可以使用单独的按钮。如何配置视图控制器以显示所选集合或在一个集合视图中实现 2 个数据源并实现切换?
const [sound,setSound] = useState(new Audio.Sound());
编辑:
我已按照说明编辑了 func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch control.selectedSegmentIndex {
case 0 :
guard let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: PhotoCollectionViewCell.identifier,for: indexPath
) as? PhotoCollectionViewCell else {
fatalError()
}
cell.configure(with: URL(string: posts[indexPath.row].postUrlString))
return cell
case 1:
guard let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: VideoCollectionViewCell.identifier,for: indexPath
) as? VideoCollectionViewCell else {
fatalError()
}
cell.configure(with: URL(string: posts[indexPath.row].postUrlString))
return cell
default:
guard let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: PhotoCollectionViewCell.identifier,for: indexPath
) as? PhotoCollectionViewCell else {
fatalError()
}
cell.configure(with: URL(string: posts[indexPath.row].postUrlString))
return cell
}
}
@objc private func controlTapped(_ sender: UISegmentedControl) {
switch control.selectedSegmentIndex {
case 0:
collectionView?.reloadData()
return
case 1:
collectionView?.reloadData()
return
default:
collectionView?.reloadData()
}
}
函数。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。