将 UIViewController 显示为没有 seguge 的 Popup

Display UIViewController as Popup without seguge

我使用了这个问题的代码 Display UIViewController as Popup in iPhone 它工作正常,但我不想使用 segue,或者我可以说我不能使用 segue,因为所有代码都是以编程方式创建的,所以我不能在按钮上设置 segue。

我使用了这段代码,但没有用

- (IBAction)open:(id)sender {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *newVC = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"Second"];
    [ViewController setPresentationStyleForSelfController:self presentingController:newVC];
    [self.navigationController pushViewController:newVC animated:YES];

}

编辑 1: 弹出后查看

你应该检查这个 VC self.navigationController 是否不为零。我认为你想要 presentViewController: 而不是 pushViewController:...