0

i would like create my function to navigate through my views.

i have a function

   func ShowView(name:String,caller:AppDelegate){


        //story board
        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

        let initViewController: UIViewController = storyBoard.instantiateViewControllerWithIdentifier(name) as UIViewController

        caller.UIWindow?.rootViewController = initViewController

}

but i need to call this function from AppDelegate and UIViewController , how can i get uiwindow from UIViewController , from AppDelegate is ok but i can't keep AppDelegate like caller parameter cause i would like that it work with UIViewController. I don't really know which i must use for my parameter.

many thanks

user2718075
  • 333
  • 2
  • 4
  • 15

1 Answers1

0

You don't need to replace rootView Controller every time if you are moving from master to details views. Connect root view to details view using segue. Set a identifier to segue in your storyboard. Overide prepareForSegue in your viewController class.


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if(segue.identifier == "showDetails")
    {
        var viewController=segue.destinationViewController as DetailsView
        //set data            
     }

}

Ram Vadranam
  • 485
  • 5
  • 14
  • accept thank, I have no button or navgationbar in my view to set a segue in my storyboard, i want load my new viewcontroller programatically. maybe you know a way to add segue without add button or navigation bar . best regards – user2718075 Mar 23 '15 at 17:42
  • it's ok , ihave find a way to add segue without button , i drag the plus after a right clik on my viewcontroller thank – user2718075 Mar 23 '15 at 17:49