![]() |
1
2
本质上,您希望创建一个视图控制器并将其存储在某个位置,直到您的应用程序释放(或者您不再需要它)后才能将其释放。这可以是您的应用程序委托、单例或任何最适合您的东西。这样,视图控制器的单个实例就是您每次想要使用它时所得到的。 下面是我将如何实现它:
(您可能希望将其作为实际的子类,而不是UIViewController,因为您可能需要将自定义数据等传递到此view controller实例)
- (UIViewController *)nowPlayingViewController { if (_nowPlayingViewController == nil) { // initialize view controller (for a storyboard, you'd do it like so, making sure your storyboard filename and view controller identifier are set properly): _nowPlayingViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"NowPlaying"]; } return _nowPlayingViewController; }
MyAppDelegate *delegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate; [self presentViewController:delegate.nowPlayingViewController animated:YES completion:nil];
您的实现可以有所不同,并根据需要进行调整以满足应用程序的需要,但这只是一个起点。 |
![]() |
Mark George · 如何在swift ui中为文本提供内部填充 1 年前 |
![]() |
Safa Ads · CDN:无法下载中继URL:https://cdn.jsdelivr.net/cocoa/Specs/2/e/c/RxSwift/3.0.0-rc.1/RxSwift.podspec.json响应:SSL连接错误 1 年前 |
![]() |
Frakcool · 满足条件时,SwiftUI动画背景颜色更改 2 年前 |