在单个 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...