I have a problem with a table created in Xcode8 and Swift 3, my table is generated by code I mean that all the contents of the table are loaded from arrays in its class and with the methods "numberOfSections" and "numberOfRowsInSection", I generate my table when the application is executed, but now my question is: how can I program the segue so that depending on the selected cell I open a new view, so I have my Main. storyboard:
I have my Table View Controller and the ones I have there are so that when I press cell 0, I send it to Savings and if I press cell 1, I send it to another view.
The complete code of the class where this table is is this:
//
// ControlTablaPrincipalTableViewController.swift
// Seccion 15
//
// Created by Barbatos on 7/10/18.
// Copyright © 2018 Seccion 15. All rights reserved.
//
import UIKit
class ControlTablaPrincipalTableViewController:UITableViewController {
var titulos : [String] = ["Caja de ahorro","Blog de la Seccion 15","Iniciar Sesion","Galeria de eventos","Convenios", "Ubicacion", "Contactanos"]
var imagenes : [UIImage] = [#imageLiteral(resourceName: "caja"),#imageLiteral(resourceName: "blog"),#imageLiteral(resourceName: "sesion"),#imageLiteral(resourceName: "galeria"),#imageLiteral(resourceName: "convenio"),#imageLiteral(resourceName: "ubicacion"),#imageLiteral(resourceName: "contacto")]
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.dataSource = self
self.tableView.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return titulos.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
cell?.imageView!.image = imagenes[indexPath.row]
cell?.textLabel?.text = titulos[indexPath.row]
return cell!
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let alert = UIAlertController(title: "Celda seleccionada", message: "Se selecciono la celda \(indexPath.row)",preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
if(indexPath.row == 0){
}
}