-1

I have 2 view controllers and want to navigate from first one to the second without any user interaction but based on variable came from http request

Edit:- 1- I tried to use segue like this: self.performSegueWithIdentifier("updateuser", sender:nil) but it return no segue with identifier 'updateuser

2- i want to create navigation based on my variable without any user interaction

//first Viewcontroller

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    let mapViewControllerObj = self.storyboard?.instantiateViewControllerWithIdentifier("update") as? hhViewController
    self.navigationController?.pushViewController(mapViewControllerObj!, animated: true)
}

}

//second viewcontroller

class hhViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = UIColor.whiteColor()


}

} enter image description here

Amal El-galant
  • 139
  • 1
  • 16

2 Answers2

0

Programmatically in Swift3..I am not sure but you can try this in your function where you getting your variable value.

if var == "variablevalue" {
     navigationController?.pushViewController(FirstController(), animated: true)
} else {
    navigationController?.pushViewController(SecondController(), animated: true)
}
Jawla
  • 333
  • 2
  • 11
  • If you didn't add any functionality in your viewDidload it will show you black view which is default. If you want to check your viewDidload working or not just change your background view color by doing - view.backgroundColor = .red – Jawla Feb 20 '17 at 10:37
  • i tried to change back ground color and it changed but it doesn't present view already exist in the storyboard – Amal El-galant Feb 20 '17 at 12:11
  • I am not storyboard type I do stuff programmatically..i found this http://stackoverflow.com/a/41095699/5891662 it might help you – Jawla Feb 20 '17 at 12:27
0

I think u do not require a segue for this. U can just push navigation Controller.

let storyBoardHome = UIStoryboard(name:storyBoardName, bundle: nil)

 let 1stViewController = storyBoardHome.instantiateViewController(withIdentifier: <1stViewControllerID>)


let 2ndViewController = storyBoardHome .instantiateViewController(withIdentifier: 2ndViewControllerID) 


self.navigationController?.pushViewController(1stViewController/2ndViewController, animated: true)
Anuraj
  • 1,242
  • 10
  • 25