【问题标题】:Get reference of baseview in a UIViewController iOS在 UIViewController iOS 中获取 baseview 的引用
【发布时间】:2015-02-09 06:56:49
【问题描述】:

如何获得对 UIViewControllers baseview 的引用。我试过这个

UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];

UIView *  baseView = keyWindow.rootViewController.view;

但是在 baseView 变量中,我得到的是 UILayoutContainerView 而不是 UIViewController 内的视图。如果我在某处错了,请纠正我。

【问题讨论】:

    标签: ios uiviewcontroller


    【解决方案1】:

    使用AppDelegate's instance 获取UIWindow,然后从中获取rootViewController,如下所示:

    UIViewController *viewController = yourObjAppDelegate.window.rootViewController;
    
    UIView *baseView = viewController.view;
    
    NSLog(@"%@ : %@",viewController,baseView);
    

    【讨论】:

      猜你喜欢
      • 2020-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-14
      • 1970-01-01
      • 2011-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多