swift3 - Can't push from programmatically created UINavigationController -


in swift 3 project using xcode 8.3 , ios 10.3, navigation controller push. app runs navigation controller until try use push. works until last line cause app crash, fatal error: unexpectedly found nil while unwrapping optional value. don't want use storyboard, point of question how accomplish task without storyboard.

app delegate code

class appdelegate: uiresponder, uiapplicationdelegate {  var window: uiwindow?      func application(_ application: uiapplication, didfinishlaunchingwithoptions launchoptions: [uiapplicationlaunchoptionskey: any]?) -> bool {          window = uiwindow(frame: uiscreen.main.bounds)          window?.makekeyandvisible()          window?.rootviewcontroller = uinavigationcontroller(rootviewcontroller: mainviewcontroller())  } 

view controller:

import uikit  class mainviewcontroller: uiviewcontroller {      override func viewdidload() {         super.viewdidload()          view.backgroundcolor = .white          let navcontroller = navigationcontroller          let myprofileviewcontroller = myprofileviewcontroller()          navcontroller!.pushviewcontroller(myprofileviewcontroller, animated: true)      } }         

move

let navcontroller = navigationcontroller let myprofileviewcontroller = myprofileviewcontroller()  navcontroller!.pushviewcontroller(myprofileviewcontroller, animated: true) 

from viewdidload viewdidappear.

in viewdidload there no parent navigation controller set , should not start animations there.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -