Hello,
Im trying to open Each vc with each Table View Cell tapped. All I have manged to do is to open one VC with all of Table View Cells. I would like each cell to have open each VC. Here is my code:
RoutesController
import UIKit
class TrasyController: UIViewController,UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return routes.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell=tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath as IndexPath) as! TableTableViewCell
cell.photo.image=self.routesImages[indexPath .row]
cell.label.text=self.routes[indexPath .row]
cell.label_car.text=self.czas_auto[indexPath .row]
cell.label_bike.text=self.czas_rower[indexPath .row]
cell.label_walk.text=self.czas_pieszo[indexPath .row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
tableView.deselectRow(at: indexPath, animated: true)
performSegue(withIdentifier: "1", sender: self)
} //Here I can perform just one VC form all cells, I need each cell to open each VC (cell with name "one" opens "route1_vc"; cell with name "two" opens "route2_vc" etc.)
@IBOutlet weak var tableView: UITableView!
let routes = [("one"),("two"),("three")]
let routesImages = [UIImage(named: "1.jpeg"), UIImage(named: "2.jpeg"), UIImage(named: "3.jpeg")]
let czas_auto = [("2h"),("75m"),("2h50m")]
let czas_rower = [("2h"),("1h25n"),("3h50m")]
let czas_pieszo = [("2h"),("2h"),("4h50m")]
let vc = ["route1_vc","route2_vc","route3_vc"]
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 120
}
TableTableViewCell:
import UIKit
class TableTableViewCell: UITableViewCell {
@IBOutlet weak var photo: UIImageView!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var label_car: UILabel!
@IBOutlet weak var label_bike: UILabel!
@IBOutlet weak var label_walk: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
Thank you in advance for your help.