定義我在裏面class AppDelegate
AppDelegate.swift文件中的變量var window: UIWindow?
,我想在裏面class xyz
其他類xyz.swift文件來使用,如Get current view controller from the app delegate (modal is possible)解釋在這裏,但我在第一行獲得任何幫助錯誤將不勝感激。這裏是從xyz.swift如何使用其它類變量是在AppDelegate中
func CurrentView() -> UIView
{
let navigationController = window?.rootViewController as? UINavigationController // Use of Unresolved identifier 'window'
if let activeController = navigationController!.visibleViewController {
if activeController.isKindOfClass(MyViewController) {
println("I have found my controller!")
}
}
}
代碼即使我使用let navigationController = AppDelegate.window?.rootViewController as? UINavigationController
錯誤是'AppDelegate.Type' does not have member named 'window'
你在哪裏定義了var windows?它是在AppDelegate類中還是在文件中?此外,CurrentView()方法在哪裏定義?請使用上下文發佈代碼。 – Abdullah
'var window:UIWindow?'在AppDelegate類中,'CurrentView()'函數是另一個名爲'class ServiceManager:NSObject {''你想要的其他代碼? –