Reputation: 3295
I have a navigation controller, a view controller, and a table view that were all created in my storyboard:
When you touch a certain row in the table view, it SHOULD push a new controller onto the navigation controller, but instead nothing happens. Here is the code:
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UINavigationController *controller = (UINavigationController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"dbNav"];
SubLevelViewController *slController = [[SubLevelViewController alloc] initWithStyle:UITableViewStylePlain];
[controller pushViewController: slController animated: YES];
}
Upvotes: 0
Views: 831
Reputation: 162
This worked for me. You have to define index path.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ServicesModel *service = [services objectAtIndex:indexPath.row];
ServiceViewController *serviceViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ServiceView"];
serviceViewController.serviceModel = service;
[self.serviceController pushViewController:serviceViewController animated:YES];
}
Upvotes: 0
Reputation: 10402
Try
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
UINavigationController *controller = self.navigationController;
SubLevelViewController *slController = [[SubLevelViewController alloc] initWithStyle:UITableViewStylePlain];
[controller pushViewController: slController animated: YES];
}
Basically instantiateViewControllerWithIdentifier
creates a new instance of the specified view controller each time you call it, so you are pushing the view in a different Navigation controller than the one that is displayed
Upvotes: 2