如果您使用的是导航控制器,则需要将ViewController推入导航堆栈。在此示例中,我在情节提要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];