0

Here is my first .xib ViewController how can I go this ViewController to storyboard ViewController

class FirstViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()




}

Here is storyboard secondViewController and I would like to go again this ViewController to .xib ViewController

class SecondViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()




}

1 Answers1

0

From .xib to .storyboard:

let sb = UIStoryboard(name: "the-name-of-the-storyboard", bundle: nil)
let ctrl = sb.instantiateViewController(withIdentifier: "SecondViewControllerIdentifier")
self.present(ctrl, animated: true, completion: nil)

Keep in mind that SecondViewControllerIdentifier is the identifier of the storyboard scene; it is not the class name of your controller

From .storyboard to .xib:

let ctrl = FirstViewController()
self.present(ctrl, animated: true, completion: nil)

Assuming that either FirstViewController.xib or First.xib exists

Andreas Oetjen
  • 9,889
  • 1
  • 24
  • 34
  • I have tried but not working it's showing Fatal error: Unexpectedly found nil while unwrapping an Optional value, can you help me? – Mahmudul Hasan Feb 18 '20 at 15:00
  • But where does it crash? Please debug. – Andreas Oetjen Feb 18 '20 at 15:02
  • 2020-02-18 21:01:55.858108+0600 pensacolabeach-dev[23632:424723] [Client] Remote object proxy returned error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated." UserInfo={NSDebugDescription=The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated.} – Mahmudul Hasan Feb 18 '20 at 15:06
  • That seems to be a problem _within_ your view controller and does not seem to be related to the initial problem. Might be related to this: https://stackoverflow.com/questions/52455652/xcode-10-seems-to-break-com-apple-commcenter-coretelephony-xpc – Andreas Oetjen Feb 18 '20 at 15:10
  • Thanks i use this now is working let sb = UIStoryboard(name: "the-name-of-the-storyboard", bundle: nil) let ctrl = sb.instantiateViewController(withIdentifier: "SecondViewControllerIdentifier") self.present(ctrl, animated: true, completion: nil) – Mahmudul Hasan Feb 18 '20 at 15:34
  • I think you forgot to add sb object, Thank you so much – Mahmudul Hasan Feb 18 '20 at 15:36
  • Yes, just a copy/paste issue :-) – Andreas Oetjen Feb 18 '20 at 22:28