I have a table view embedded in my view controller, and I want to be able to setup segues to four other view controllers depending on what cell in the view controller is clicked.
However, I can't seem to figure out how to control+drag a segue from the table view to a view controller.
I believe the relevant section of code would be:
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let options = ["Home", "My Account", "Settings", "Support"]
//MARK: Properties
var selectedItem: String?
@IBOutlet weak var nameTextField: UILabel!
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath)
cell.textLabel?.text = options[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return options.count
}
//MARK: Actions
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let selectedRow = tableView.cellForRow(at: indexPath){
selectedItem = selectedRow.textLabel?.text
}
if selectedItem == "My Account"{
performSegue(withIdentifier: "classifySegue", sender: self)
} else if selectedItem == "Settings"{
performSegue(withIdentifier: "otherSegue", sender: self)
}
}
}
This would be the view and storyboard:
The problem is the current otherSegue comes from the View Controller and not the Table View itself.