我似乎无法在没有访问UINavigationController
的情况下获得最顶层的UIViewController
。以下是我的代码:
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(vc, animated: true, completion: nil)
然而,它似乎没有做任何事情。 keyWindow
和 rootViewController
似乎也是非空值,因此可选链不应该是一个问题。
注意: 像这样做是一个坏主意。 它会破坏MVC模式。