1

I am implementing FB Login. I have instantiated the FBSDKLoginButton() and added it to view directly from my ViewController.swift file (created and presented through the source code).

Normally I present a view modally by dragging and connecting the button to the new view in Interface Builder. However this button does not exist in my storyboard. How can I complete this task, but directly from my ViewController.swift file.

2 Answers2

3

You can add manual segues from one ViewController to other ViewController.

In your FirstViewController in storyboard :

enter image description here

Connect the segue.

Then select the connected segue and add Identifier:

enter image description here

Now you can use:

self.navigationController?.performSegue(withIdentifier: <The Identifier name>, sender: <If you want to send some data with it>)

you can use prepare(for segue: UIStoryboardSegue, sender: Any?):

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

}

to send data to the SecondViewCntroller.

Hope this helps.

pacification
  • 5,838
  • 4
  • 29
  • 51
Amit
  • 4,837
  • 5
  • 31
  • 46
1

Direct segue needs a connection from UI object to other view-controller. Rather segue, you can use pushViewController:

enter image description here

let sb = UIStoryboard(name: "Main", bundle: Bundle.main)
if let viewcontroller = sb.instantiateViewController(withIdentifier: "storyboardIdentifier") as? YourViewController {
    self.navigationController?.pushViewController(viewcontroller, animated: true)
}
Ankit Jayaswal
  • 5,549
  • 3
  • 16
  • 36