ios - Navigating between two viewController -


i have set initial viewcontroller rootviewcontroller in appdelegate because don't use storyboard. looks way:

var window: uiwindow? var mainnavigationcontroller: uinavigationcontroller?  func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool {      self.mainnavigationcontroller = uinavigationcontroller()     var maincontroller: uiviewcontroller? = tinelineviewcontroller()     self.mainnavigationcontroller!.pushviewcontroller(maincontroller!, animated: true)     self.window = uiwindow(frame: uiscreen.mainscreen().bounds)     self.window!.rootviewcontroller = maincontroller     self.window!.makekeyandvisible()      ...        ... 

my application running , tinelineviewcontroller shows up.

i have in class uibutton call method:

  func postleft(_sender: anyobject?)     {         println("go secound view..")         let secondviewcontroller = postcreatecontroller()          let appdelegate = (uiapplication.sharedapplication().delegate as! appdelegate)         self.navigationcontroller?.presentviewcontroller(secondviewcontroller, animated: true, completion: nil)         appdelegate.window?.rootviewcontroller = secondviewcontroller     } 

this way if push button screen change , secondviewcontroller shows up, without animation...

if try change view way:

self.navigationcontroller?.pushviewcontroller(secondviewcontroller, animated: true) 

it's still don't have animations , after secoundviewcontroller shows application crash message:

* terminating app due uncaught exception 'uiviewcontrollerhierarchyinconsistency', reason: 'adding root view controller child of view controller:' * first throw call stack: (

i don't know if best way set rootviewcontroller class in appdelagate , why can't navigate without adding line potleft function:

appdelegate.window?.rootviewcontroller = secondviewcontroller 

without line can see in app consol, secondviewcontroller viewdidload method called, controller not shows up, , message cosole:

warning: attempt present on view not in window hierarchy!

how navigate between 2 view without use storyboard?

1) set mainnavigationcontroller rootviewcontroller 2) use self.navigationcontroller?.pushviewcontroller(secondviewcontroller, animated: true)

explanation

logically root view controller uinavigationcontroller while setting tinelineviewcontroller app's delegate rootviewcontroller property. why you're getting exception.

self.mainnavigationcontroller = uinavigationcontroller() var maincontroller: uiviewcontroller? = tinelineviewcontroller() self.mainnavigationcontroller!.pushviewcontroller(maincontroller!, animated: true) self.window = uiwindow(frame: uiscreen.mainscreen().bounds) // error here // self.window!.rootviewcontroller = maincontroller  // root view controller should navigation controller self.window!.rootviewcontroller = mainnavigationcontroller  self.window!.makekeyandvisible() 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -