我正在尝试切换到特定的 ViewController,它是 Storyboard的一部分,但应用程序一直崩溃。我希望过渡具有“模态”风格。
请注意,我要切换到的 View 没有.xib 文件
这是我正在使用的代码:
NSString * storyboardName = @"MainStoryboard";
NSString * viewControllerID = @"GalleryViewController";
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
GalleryViewController * controller = (GalleryViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];
[self presentViewController:controller animated:YES completion:nil];
最佳答案
您可以使用 segue 来做到这一点。
首先,在您的 Storyboard中,从呈现 View Controller (代码中的“self”)“控制 + 拖动”到目标 Controller (您的 GalleryViewController)。此 segue 不与任何 subview 或小部件相关联。
其次,在属性检查器中,为其命名为“ToGalleryVCSegue”,并将类型设置为“Modal”。
最后,在代码中,简单地做:
[self performSegueWithIdentifier: @"ToGalleryVCSegue" sender: self];
关于ios - 以编程方式跳转到特定 View ,该 View 已经是 Storyboard的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17686306/