import Foundation
import UIKit
class ServiceLines: UIViewController{
@IBOutlet weak var servicesTableView: UITableView!
var ServiceA: [Service] = []
var identities = [String]()
override func viewDidLoad(){
super.viewDidLoad()
ServiceA = Services()
identities = ["Service1","Service2","Service3"]
}
func Services() -> [Service]{
var releaseServices: [Service] = []
let Service1 = Service(titled: "Test1", description: "Test", image: #imageLiteral(resourceName: "Test"))
let Service2 = Service(titled: "Test2", description: "Test", image: #imageLiteral(resourceName: "Test"))
let Service3 = Service(titled: "Test3", description: "Test", image: #imageLiteral(resourceName: "Test"))
releaseServices.append(Service1)
releaseServices.append(Service2)
releaseServices.append(Service3)
return releaseServices
}
}
extension ServiceLines: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return ServiceA.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let ServiceB = ServiceA[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier:"ServicesTableViewCell") as! ServicesTableViewCell
cell.setServices(service: ServiceB)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
func prepareForSegue(segue: UIStoryboardSegue, sender: Any) {
let vcName = identities[indexPath.row]
let viewController = storyboard?.instantiateViewController(withIdentifier: vcName)
self.navigationController?.pushViewController(viewController!, animated: true)
}
}
}
the cell is filled with the correct data but when I click on a cell in the simulator it does not move to the corresponding view controller above is the code. also how can I move specific data that is filled inside of the cell such as text and image assets to the corresponding view controller (should I add it in each corresponding swift file for that specific view or is their an easier way)?