我目前有一个UICollectionView
表与单元格,我试图让每个单元格被创建有自己独特的视图控制器。例如,当点击UICollectionViewCell
时,视图控制器将显示该特定单元格。我知道我可以创建一个viewcontroller并执行segue只有一个视图控制器。这只涵盖了一个单元格...如果用户创建了25个单元格......我如何为每个单元格创建视图控制器而无需创建一个segue?下面的代码是创建一个单元格。创建新的视图控制器UICollectionViewCell点击
// MARK: Create collection View cell with title, image, and rounded border
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! ChatCell
let object = objects[indexPath.row]
cell.chatLabel.text = object.title ?? ""
cell.chatImage.image = object.image
if let chatImagePath = object.imagePath {
if let imageURL = URL(string: chatImagePath) {
cell.chatImage.sd_setImage(with: imageURL)
}
}
cell.layer.borderWidth = 0.5
cell.layer.borderColor = UIColor.darkGray.cgColor
cell.layer.masksToBounds = true
cell.layer.cornerRadius = 8
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return objects.count
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let itemWidth = photoCollectionView.bounds.width
let itemHeight = photoCollectionView.bounds.height/2
return CGSize(width: itemWidth, height: itemHeight)
}
但是,您是否真的有这些目标视图控制器的25个完全不同的设计?或者他们是同一种基本类型的视图控制器,只是显示不同的数据? – Rob
@Rob我想为该单元格创建一个视图控制器...我不能让所有的单元格都指向相同的视图控制器 –
@Rob是他们都有相同的布局,但我想发布不同的数据在每个 –