好的。因此,我浏览了网络并阅读了有关此相对较新的 iOS 警告的类似问题。我的应用程序不使用 Storyboard。我只有一个简单的问题。什么是“分离 View Controller ”,任何人都可以提供一个明确的引用(例如 Apple 文档)来提供“分离 View Controller ”的定义,因为我们将在此警告的上下文中理解它。如果没有人真正准确地理解分离的 View Controller 是什么,我看不出这个问题的其他答案比围绕该主题的摸索和猜测更多。
最佳答案
分离的 View Controller 当前不在 [[[UIApplication sharedApplication] keyWindow] rootViewController]
例如,我可以在我的代码中的任何地方实例化一个 UIViewController,但是如果我从不将它放在这个层次结构中,方法是将它设为我的 rootViewController
或插入我的 rootViewController< 中的导航堆栈
,那么当我在上面展示一些东西时,我会得到奇怪的/未定义的行为。
示例:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIViewController* a = [[UIViewController alloc] init];
UIViewController* b = [[UIViewController alloc] init];
UIViewController* someOtherVC = [[UITableViewController alloc] init];
self.window.rootViewController = a;
//Works fine :)
[a presentViewController:someOtherVC animated:YES completion:nil];
//might break the world
[b presentViewController:someOtherVC animated:YES completion:nil];
}
关于ios - 不鼓励在分离的 View Controller 上呈现 View Controller - "detached view controller"的定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33378618/