ios - 不鼓励在分离的 View Controller 上呈现 View Controller - "detached view controller"的定义?

标签 ios uiviewcontroller

好的。因此,我浏览了网络并阅读了有关此相对较新的 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/

相关文章:

ios - dismissViewControllerAnimated :completion: not executed

ios - 保持多个用户偏好的最佳方法(NSUserDefaults、XML 文件或数据库)

ios - 在模态视图中使用导航 Controller 将 managedobjectContext 传递给 tabbarcontroller

ios - 来自容器 ViewController 的 UIPopOverPresentationViewController

ios - 将 View Controller 添加到另一个时的自定义转换

ios - Xcode 重新创建 UIViewController 可能吗?

ios - 如何保存结果集并在 TableView 中显示所有数据

ios - 结合许多 UIViewPropertyAnimators

ios - UIProgressView 未按预期更新

iphone - 在其他 View Controller 下面创建一个 View Controller