私のアプリケーションのショートカットアイテムの代理人に3Dタッチ機能があり、3DタッチアイテムがiPhoneからクリックされたときにViewControllerをインスタンス化する必要があります。3d touch swift 3 viewcontrollerを開けません
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
if shortcutItem.type == "com.kevinvugts.addStuf" {
let sb = UIStoryboard(name: "Main", bundle: nil)
let exerciseVC = sb.instantiateViewController(withIdentifier: "exerciseVC") as! exerciseVC
let root = UIApplication.shared.keyWindow?.rootViewController
root?.present(exerciseVC, animated: false, completion: {() -> Void in
completionHandler(true)
})
}
}
この警告/エラーでこのコードの結果:ここで
はコードである
Warning: Attempt to present <ActiveRest.exerciseVC: 0x131d39320> on <ActiveRest.ViewController: 0x131d0e470> whose view is not in the window hierarchy!
が遅延して行うには、この何かをしていますか?
ありがとうございました!
親切にしてください。
これはapp delegate sir –
で呼び出されます。あなたの 'viewHierarchy'が' appdelegate'で準備ができていないので、あなたは 'appdelegate'からviewcontrollerを提示できません! – Lion
私はこのチュートリアルを見て、全く同じことをしました:https://www.youtube.com/watch?v=NO9E5KxixOw –