如果您使用的是导航控制器,则需要将 ViewController 推入导航堆栈。在此示例中,我在 Storyboard ID 设置中将 ViewController 命名为“VDI”。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
YourVC *dest = [storyboard instantiateViewControllerWithIdentifier:@"VDI"];
[self.navigationController pushViewController:dest animated:YES];
如果您不希望 NavigationController 继续将自己添加到“返回”历史记录中,您可以在添加之前弹出堆栈,就像这样。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
YourVC *dest = [storyboard instantiateViewControllerWithIdentifier:@"VDI"];
UINavigationController *navController = self.navigationController;
[navController popViewControllerAnimated:NO];
[navController pushViewController:dest animated:YES];