Reputation: 3367
I have a simple table view that when I click on the cell, I want it to open a new UIViewController. Currently I have it so that it goes to a particular View Controller now, but it seems as if every cell leads to the same View Controller. I want each one to go to a different one. Here is my attempt:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var indexPath = self.tableView.indexPathForSelectedRow()
let navController = self.storyboard?.instantiateViewControllerWithIdentifier("ChatController") as UINavigationController
navController.hidesBottomBarWhenPushed = true
let chatController = navController.viewControllers.first as ChatController
chatController.currentUserName = self.firstName + " " + self.lastName
chatController.chatWith = chatNames[indexPath!.row]
chatController.currentUserObjectID = self.objectID
}
However, this doesn't seem to work as I get an error saying Storyboard doesn't contain a view controller with identifier 'ChatController''
. If it helps, the segue first goes through a navigation controller then to the desired view controller.
Upvotes: 0
Views: 625
Reputation: 2052
In the UITableViewDelegate method (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
call [self performSegueWithIdentifier:kSegueIdentifier sender:self];
And, according to the indexPath you can set a different value that will be passed to your next view controller through the method prepareForSegue
.
Upvotes: 1