简体   繁体   English

故事板:从子视图弹出到根视图控制器

[英]Storyboard : Pop to root view controller from subview

this is my first app so this should be simple for experienced ios developer. 这是我的第一个应用程序,因此对于有经验的ios开发人员来说应该很简单。 I have a story board with navigation controller and in one of my view controller there is a subview. 我有一个带有导航控制器的故事板,并且在我的一个视图控制器中有一个子视图。 On click in subview, I want to return to the root controller but unfortunately it is not working. 在子视图中单击时,我想返回到根控制器,但是不幸的是它没有用。 Subview Controller 子视图控制器

- (IBAction)doneAction:(id)sender {
    if ([self.parentViewController isKindOfClass:[PlayViewController class]]){
        PlayViewController *pControl = (PlayViewController *) self.parentViewController;
        [pControl goToMainView];
    }else{
        NSLog(@"NOT AN INSTANCE");
    }
}

View Controller 查看控制器

-(void)goToMainView{
    NSLog(@"I AM HERE");
    [self.navigationController popToRootViewControllerAnimated:YES];
    /*SWRevealViewController *secondViewController =
    [self.storyboard instantiateViewControllerWithIdentifier:@"gameController"];
    [self performSegueWithIdentifier:@"gameView" sender:self];
    [self.navigationController pushViewController:secondViewController animated:YES];*/
}

Any help is appreciated. 任何帮助表示赞赏。 Thank you 谢谢

This is how my storyboard looks like 这就是我的故事板的样子 故事板

Seems like one of the connections from root view to view controller in the attached screenshots is modal (or both?). 在所附的屏幕快照中,似乎从root viewview controller的连接之一是modal (或两者都是?)。
In this case the view controller is not part of navigation controller stack. 在这种情况下, view controller不是导航控制器堆栈的一部分。

Try to change the types of these 2 segues to push . 尝试更改要push的这两个序列的类型。
This should add each of these view controllers to navigation controller's views stack and each of them will have a non-nil navigationController property. 这应该将每个视图控制器添加到导航控制器的视图堆栈中,并且每个视图控制器将具有一个非null navigationController属性。

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

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