我用我的AppDelegate以下彈出警報用戶在收到推送:接收錯誤:類型的UIViewController「的價值還沒有成員「openViewControllerBasedOnIdentifier」
let topWindow = UIWindow(frame: UIScreen.main.bounds)
topWindow.rootViewController = UIViewController()
topWindow.windowLevel = UIWindowLevelAlert + 1
let alert = UIAlertController(title: "message", message: "message", preferredStyle: .alert)
let yesButton = UIAlertAction(title: "OK", style: .default, handler: {(_ action: UIAlertAction) -> Void in
print("you pressed Yes, please button")
topWindow.isHidden = true
topWindow.rootViewController?.openViewControllerBasedOnIdentifier("consumerProfile")
})
let noButton = UIAlertAction(title: "CANCEL", style: .default, handler: {(_ action: UIAlertAction) -> Void in
print("you pressed No, thanks button")
topWindow.isHidden = true
})
alert.addAction(yesButton)
alert.addAction(noButton)
topWindow.makeKeyAndVisible()
topWindow.rootViewController?.present(alert, animated: true, completion: { _ in })
我的問題是:
topWindow.rootViewController?.openViewControllerBasedOnIdentifier("consumerProfile")
功能openViewControllerBasedOnIdentifier
僅適用於基於名爲BaseViewController
這樣一個特定的UIViewController
類的意見存在,我收到以下錯誤:
Value of type 'UIViewController' has no member 'openViewControllerBasedOnIdentifier'
你有什麼問題?您無法提供來自AppDelegate的提醒或您發佈的錯誤? –
你只需將你的'rootViewController'設置爲一個空的'UIViewController'。你如何期待能夠在這個'UIViewController'上調用你自定義的'BaseViewController'的方法? – rmaddy
你見過這個:https://stackoverflow.com/questions/30592521/opening-view-controller-from-app-delegate-using-swift –