Frank Boccia Frank Boccia - 2 years ago 70
Swift Question

UITableView Cell to a new ViewController

I am trying to go from a

UITableView Cell
, when tapping the Cell, to go to another
in swift. I have a
called MainMenu which is my
and I am trying to click on a cell, and go to my other
. Can someone please help?

My code for the UITableView called Main Menu:

class MainMenu: UITableViewController {

// Set Tabs in Table View Controller
var tabs = [String]()

override func viewDidLoad() {

// Name of Tabs
tabs = ["Scanner","QR-Codes","Cargo","Matrix","Xbox","PS4","Nintendo","Sega","Dreamcast","Xbox360","GameCube","Wii","Challenger","Mustang","Macbook","Logitech"]
override func didReceiveMemoryWarning() {
// Dispose of any resources that can be recreated.
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tabs.count
// Set Tabs in View
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("scannerCell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel!.text = tabs[indexPath.row]
// return
return cell

Answer Source

First you need to embed your mainmenu controller with Navigation controller in story board After that add this method in your mainmenu controller

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let detailVC = self.storyboard.instantiateViewControllerWithIdentifier("detailViewController") as! DetailViewController
    self.navigationController.pushViewController(detailVC , animated: true)

Hope this will help.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download