简体   繁体   中英

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?

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.

在此处输入图片说明

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

在此处输入图片说明

Build and run your app.

确保“ self.navigationController”不是零,“ vc”不是零

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM