简体   繁体   English

选择表格视图单元格时无法推送视图控制器

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

I'm using Objective-C. 我正在使用Objective-C。 I want to push a new vier controller when I select a table view cell. 选择表格视图单元格时,我想推送一个新的vier控制器。 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". 我的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. 拿一个导航控制器,将当前的控制器从您的didSelectRowAtIndexPath调用到故事板中的根控制器。 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: 然后用鼠标右键单击拖动到您的当前控制器,并将其设置为“ root view controller”,如下所示:

在此处输入图片说明

Build and run your app. 生成并运行您的应用程序。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法以编程方式选择表格视图单元格 - Can't select table view cell programmatically 我无法在Swift中删除最后一个表格视图单元格 - I can't delete my last table view cell in Swift 无法从UITableView单元格推送新的视图控制器 - Can't push a new view controller from UITableView cell 我可以将页面视图控制器放在表格视图单元格中吗? - Can I put a page view controller within a table view cell? 无法从Web View Controller加载推入URL - Can't load a push url from my Web View Controller 无法在表视图控制器中为单元格设置自定义类 - Can't set custom class for cell in table view controller 为什么我不能在NavigationController中推送视图控制器? - Why i can not push a view controller in my navigationController? 当我在表格视图中选择一个单元格时,我的应用程序崩溃了,但是我找不到在代码崩溃的地方 - My app crashes when I select a cell on a table view but I cant find where in the code it crashes 如何将选定的集合视图单元格的图像推送到另一个视图控制器? - How Can I push the image of selected Collection View Cell to another View Controller? 无法让 UI 测试选择静态表格视图单元格 - Can't get UI Testing to select a static table view cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM