Hongxu Jin
Hongxu Jin

Reputation: 807

Can't push my view controller when I select a table view cell

I'm using Objective-C. I want to push a new vier controller when I select a table view cell. This is my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    detailViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"detailVC"];
    //something
    [self.navigationController pushViewController:vc animated:YES];
}

I have a detail view controller in my storyBoard and set its storyboard ID "deatilVC". But when I select a table view cell, the simulator freezes. Someone can help me?

Upvotes: 0

Views: 94

Answers (2)

trandy
trandy

Reputation: 11

make sure "self.navigationController" is not nil and "vc" is not nil

Upvotes: 0

Jaimish
Jaimish

Reputation: 629

Take one navigation controller and make the current controller from where your didSelectRowAtIndexPath will call to it's root controller in storyboard. Check the following example.

enter image description here

And then drag with right click of mouse to your current controller and make it "root view controller" just like below:

enter image description here

Build and run your app.

Upvotes: 1

Related Questions