我有这个主页是PhotoStreamViewController,它有一个CollectionView,我想要发生的是当我从PhotoStreamController点击collectionView的一张图片时,它会自动转到DetailStreamController的页面集合View然后我可以从PhotoStreamViewController向左和向右滑动相同的照片,我的问题是从PhotoStreamViewController到DetailStreamController的segue。 导入UIKit
class Photo {
class func allPhotos() -> [Photo] {
var photos = [Photo]()
if let URL = Bundle.main.url(forResource: "Photos 2", withExtension: "plist") {
print(URL)
if let photosFromPlist = NSArray(contentsOf: URL) {
print(photosFromPlist)
for dictionary in photosFromPlist {
let photo = Photo(dictionary: dictionary as! NSDictionary)
photos.append(photo)
}
}
}
return photos
}
var image: UIImage
init(image: UIImage) {
self.image = image
}
convenience init(dictionary: NSDictionary) {
let photo = dictionary["imageName"] as? String
let image = UIImage(named: photo!)?.decompressedImage
self.init(image: image!)
}
}
这是我的PhotoStreamController代码
import UIKit
class PhotoStreamViewController: UIViewController,UICollectionViewDataSource, UICollectionViewDelegate {
var parentController: UIViewController?
@IBOutlet var photoStream: UICollectionView!
var photos = Photo.allPhotos()
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let cell = sender as? UICollectionViewCell {
if let indexPath = self.photoStream?.indexPath(for: cell) {
if segue.identifier == "StreamToStreamDeatilController" {
let photoViewController : StreamDetailController = segue.destination as! StreamDetailController
photoViewController. " I dont know what to put here" this is the missing code. cause I cant access the Class Photo
}
}
}
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return photos.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cellA = collectionView.dequeueReusableCell(withReuseIdentifier: "Celler", for: indexPath) as! AnnotatedPhotoCell
cellA.box = Box(fImage: photos[indexPath.row].image)
return cellA
}
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let paper = photoDataSource.photoForItemAtIndexPath(indexPath) {
performSegue(withIdentifier: "StreamToStreamDeatilController", sender: paper)
}
}
}