我有 3 个视图控制器“根”、“父”和“子”。现在我正在从 Parent 的方法中推入 Child。现在,当我想通过以下代码从子视图弹出到父级时:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
Parent *svc = [storyboard instantiateViewControllerWithIdentifier:@"Parent"];
[self.navigationController popToViewController:svc animated:YES];
这显示了错误:
'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.'
当我改为编写以下代码时,它会弹出一个空白屏幕!:
[self.navigationController popViewControllerAnimated:YES];
当我编写以下代码时,它会弹出到 Root。:
[self.navigationController popToRootViewControllerAnimated:YES];
但我想准确地弹出到父视图。我该怎么做?
提前致谢。
从类 Parent 推送示例:
-(void)Custom{
if([info isEqualToString:@"message"]){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
Child *cd = [storyboard instantiateViewControllerWithIdentifier:@"Child"];
[self.navigationController pushViewController:cd animated:YES];
}
}
来自 Child 的流行示例:
-(void)viewDidLoad{
[super viewDidLoad];
[self sendMessage]
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
Parent *svc = [storyboard instantiateViewControllerWithIdentifier:@"Parent"];
[self.navigationController popToViewController:svc animated:YES];
}