问题描述
我需要一个 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 (将#修改为@)