正如 JoePasq 所建议的那样,“让您的视图控制器类成为导航控制器的根视图控制器”。选择要设置为根屏幕的视图控制器并转到编辑器/嵌入选项并选择导航控制器。您将获得一个嵌入您的根视图控制器的导航控制器。您可以在程序中以编程方式更改屏幕,而不是设置 segue。在您的按钮单击事件方法中,编写如下类似的代码;
- (IBAction)okPressed:(id)sender {
UIStoryBoard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; //MainStoryboard is the name of your storyboard
SecondViewController *secondView = [storyboard instantiateViewControllerWithIdentifier:@"sView"];
//sView is the identifier name set by the user, (present inside Attribute Inspector - View Controller)
[self.navigationController pushViewController:secondView animated:YES];
让我知道这是否有效,或者还有其他方法可以做到这一点。