加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 获取最高的UIViewController

发布时间:2020-12-14 06:09:26 所属栏目:百科 来源:网络整理
导读:我似乎无法获得最高的UIViewController没有访问UINavigationController。这里是我到目前为止: UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(vc,animated: true,completion: nil) 然而,它似乎没有做任何事情。
我似乎无法获得最高的UIViewController没有访问UINavigationController。这里是我到目前为止:
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(vc,animated: true,completion: nil)

然而,它似乎没有做任何事情。 keyWindow和rootViewController似乎也是非nil值,所以可选的链接不应该是一个问题。

提前致谢!

注意:这样做是一个坏主意。它打破了MVC模式。

presentViewController显示一个视图控制器。它不返回视图控制器。如果你没有使用UINavigationController,你可能正在寻找presentedViewController,你需要从根开始,遍历呈现的视图。
if var topController = UIApplication.sharedApplication().keyWindow?.rootViewController {
    while let presentedViewController = topController.presentedViewController {
        topController = presentedViewController
    }

    // topController should now be your topmost view controller
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读