我已经拥有自定义表格视图单元格的数据数组。目前只包含一个imageView和标签。
我想使用imageView将单个缩略图图像作为大版本显示为单独的视图控制器。但是,当然,使用我的数据数组,以便在主机imageView中加载正确的图像。
基本上,我想创建一个主机imageView,当我从列表中选择数据时,它将加载我的数据数组。
我当前的数组如下:
j < 4
PictureCell:
import UIKit
class PictureViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var pictures: [picture] = []
override func viewDidLoad() {
super.viewDidLoad()
pictures = createArray()
tableView.rowHeight = 120
tableView.delegate = self
tableView.dataSource = self
}
func createArray() -> [picture] {
var tempPictures: [picture] = []
let picture1 = picture(image: #imageLiteral(resourceName: "Arteries Hand"), title: "Arteries Hand")
let picture2 = picture(image: #imageLiteral(resourceName: "Arteries Upper Arm"), title: "Arteries Upper Arm")
let picture3 = picture(image: #imageLiteral(resourceName: "Arteries Shoulder"), title: "Arteries Shoulder")
let picture4 = picture(image: #imageLiteral(resourceName: "Arteries Upper Limb"), title: "Arteries Upper Limb")
tempPictures.append(picture1)
tempPictures.append(picture2)
tempPictures.append(picture3)
tempPictures.append(picture4)
return tempPictures
}
}
extension PictureViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return pictures.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let picture = pictures[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "pictureCell") as! pictureCell
cell.setPicture(picture: picture)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "segue", sender: self)
}
}
答案 0 :(得分:0)
performSegue(withIdentifier: "segue", sender: self)
上述方法触发了以下类方法,您可以使用它来传输数据:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let segueId = segue.identifier else { return }
switch segueId {
case "segue":
let destinationVC = segue.destination as! YournextVC
destVC.pictures = self.pictures // This is how you transfer info to the next View Controller
default:
break
}
}