【发布时间】:2019-10-11 15:11:13
【问题描述】:
我对 swift 还很陌生,有一个问题想问。
我有三个 ViewController,前两个有集合视图,最后一个没有。
我有它,以便第一个控制器在集合视图中显示两个数组。第一个是字符串数组,第二个是图像数组,这是为了让它们在集合视图上正确排列。
这是我很难理解的。当单击集合视图单元格时,我如何让它转到第二个控制器(那里有另一个集合视图)并显示一个完全不同的数组。我希望它每次单击第一个控制器的每个单元格都会显示一个不同但特定的数组。
点击第二个视图控制器集合单元格后,它将转到带有图像、标签和文本视图的视图控制器,本质上我需要为每个点击的单元格显示一组不同的数据。
我真的不知道从哪里开始,我相信这可能与字典有关,但我不知道从哪里开始。
这是我用于第一个带有集合视图的视图控制器的代码
class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
collectionView.delegate = self
collectionView.dataSource = self
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize{
return CGSize(width: 160.0, height: 210.0)
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return labelArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CollectionViewCell
cell.imageView.image = imageArray[indexPath.item]
cell.label.text = labelArray[indexPath.item]
return cell
}
}
我只是不知道从这里去哪里,任何帮助将不胜感激! 谢谢]1
【问题讨论】: