How to create a segue to a Table View Controller Scene directly in a swift class file?
How to create a segue to a Table View Controller Scene directly in a swift class file?
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).
FBSDKLoginButton()
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 Answers
2
You can add manual segues from one ViewController to other ViewController.
ViewController
ViewController
In your FirstViewController in storyboard :
FirstViewController
storyboard

Connect the segue.
segue
Then select the connected segue and add Identifier:
segue
Identifier

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?):
prepare(for segue: UIStoryboardSegue, sender: Any?)
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
to send data to the SecondViewCntroller.
SecondViewCntroller
Hope this helps.
Direct segue needs a connection from UI object to other view-controller. Rather segue, you can use pushViewController:
pushViewController

let sb = UIStoryboard(name: "Main", bundle: Bundle.main)
if let viewcontroller = sb.instantiateViewController(withIdentifier: "storyboardIdentifier") as? YourViewController
self.navigationController?.pushViewController(viewcontroller, animated: true)
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
so you need to push to another viewController programmatically in your button click??
– Shezad
Sep 6 '18 at 5:57