I am trying to connect one prototype cell to two different segue pathways that each lead to another view controller. I read in another posts that hooking up the segues has to be done from the source view controller itself to the destination view controller, not the prototype cell to the view controller.
My source view controller is called BuildsViewController, which is populated with tableview cells. I am working on an app where clicking the cell will open up the destination view controller based on whether the login or guest button was clicked at the root view controller. (buttonClicked is an instance variable that stores the button that the user clicked on the root view controller).
When I click on the cell on BuildsViewController, however, nothing happens. Where did I go wrong? Note that the login button has tag 0 and the guest button has tag 1.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
switch self.buttonClicked?.tag {
case 0?:
performSegue(withIdentifier: "showLogin", sender: self)
break;
case 1?:
performSegue(withIdentifier: "showGuest", sender: self)
break;
default:
preconditionFailure()
}
}
override func prepare (for segue: UIStoryboardSegue, sender: Any?) {
switch segue.identifier {
case "showLogin"?:
if let row = self.tableView.indexPathForSelectedRow?.row {
let build = self.buildStore.allBuilds [row]
let detailBuildsViewController = segue.destination as! BuildDetailViewController
detailBuildsViewController.build = build
break;
}
case "showGuest"?:
if let row = self.tableView.indexPathForSelectedRow?.row {
let build = self.buildStore.allBuilds [row]
let detailBuildsViewControllerGuest = segue.destination as! BuildDetailViewControllerGuest
detailBuildsViewControllerGuest.build = build
break;
}
default:
preconditionFailure("Unexpected segue identifier")
}
}
override func tableView (_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
let build = buildStore.allBuilds [indexPath.row]
cell.textLabel?.text = build.name
return cell
}
Thank you!
cellForRowAtcode - Zonily Jame