Adrian
Adrian

Reputation: 20068

Push a new view controller with navigation controller

So I created a new view controller which has the Custom class named DescriptionViewController. And from my current view controller inside didSelectRowAtIndexPath I use this code:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    DescriptionViewController *descriptionViewController = [[DescriptionViewController alloc] initWithNibName:@"DescriptionViewController" bundle:nil];
    [self.navigationController pushViewController:descriptionViewController animated:YES];
}

But nothing happens when I click on a cell. Is there anything more I need to do ?

Upvotes: 0

Views: 1317

Answers (2)

Abdullah Shafique
Abdullah Shafique

Reputation: 6918

Select your viewcontroller in the storyboard and on top go to editor->embed in->navigation controller then instead of initWithNibName try just init

Upvotes: 1

JonahGabriel
JonahGabriel

Reputation: 3094

If you put in a breakpoint and it is stopping in the didSelectRowAtIndexPath, my guess is that your self.navigationController is nil.

If you are using storyboards, make sure your entry point is a UINavigationController and not a UIViewController.

If you loading this view controller though a modal transition, make sure you push on a navigation controller with this view controller as the root view instead.

Upvotes: 2

Related Questions