1

I have one problem, i want call one method from firstVC to seccondVC i try to use such code:

let storyboard: UIStoryboard = UIStoryboard.init(name: "MainScreenVC", bundle: nil)
let firstViewController: MainScreenVC = storyboard.instantiateViewController(withIdentifier: "MainScreenVC") as! MainScreenVC
firstViewController.automatingFullFill()

But immediately i received error, what is wrong?

My error:

'Could not find a storyboard named 'MainScreenVC' in bundle NSBundle

5
  • what this function do ? and MainScreenVC is already initiated or this is first time initialisation ? Commented May 21, 2018 at 6:12
  • You are giving Storyboard name and viewcontroller as same,make sure that Storyboard name and ViewController name is same . Commented May 21, 2018 at 6:16
  • It's sure same name Commented May 21, 2018 at 6:17
  • If you didn't change your storyboard name then it will be 'Main' not MainScreenVC. so use let storyboard: UIStoryboard = UIStoryboard.init(name: "Main", bundle: nil) Commented May 21, 2018 at 6:18
  • Yes, now it's working, thanks. Commented May 21, 2018 at 6:21

1 Answer 1

2

If you are taking seperate storyboard for every viewcontroller you have to give storyboard name and viewcontroller name .

let storyboard: UIStoryboard = UIStoryboard.init(name: "give storyboard name here ", bundle: nil)
let firstViewController: MainScreenVC = storyboard.instantiateViewController(withIdentifier: "viewcontrollername here") as! MainScreenVC
firstViewController.automatingFullFill()

(OR) You can call it like this also

 let mainScreenVC = UIStoryboard.init(name: "give Storyboard name here", bundle: nil).instantiateViewController(withIdentifier: "viewcontroller") as! MainScreenVC
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.