我想要发生的是,当我点击ViewController中的照片时,它会自动转到DetailViewController,下面是tableViewController上的标签,以及来自DataSource的数据。以及如何在我的tableView中将图像标题用作字符串。 This
DataSource的代码
import UIKit
class DataSource: NSObject, UICollectionViewDataSource, UICollectionViewDelegate {
var carsToDisplay: [Car] = []
var image : ImageCollectionViewCell!
var views: ViewController!
override init() {
super.init()
//This is the Data I want to show up at my tableView
carsToDisplay = [Car(name: "Tim", price: 123, image: UIImage(named: "1")),Car(name: "T9m", price: 123, image: UIImage(named: "2"))]
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return carsToDisplay.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! ImageCollectionViewCell
let car = carsToDisplay[indexPath.item]
cell.imageView.image = car.image
return cell
}
}
我的DetailViewController中的代码
import UIKit
class DetailViewController: UIViewController, UICollectionViewDataSource, UITableViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var tableView: UITableView!
var savedImage : [Car] = []
var carsToDisplay: [Car] = []
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return carsToDisplay.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
//How do I put the Image title as a String?
let car = carsToDisplay[indexPath.item]
cell.textLabel?.text = car.name!
return cell
}
}