2

I'm trying to use a Customizable PageMenuViewController in Swift from cocoapods :Link

I want to load my already made views but all I get is a blank page

this is the function to load views:

  func viewControllers(forPageMenuController pageMenuController: PageMenuController) -> [UIViewController] {

        let detailVC = HomeViewController()
        let vc : UIViewController = detailVC as UIViewController
        let detailVC1 = SearchViewController()
        let vc1 : UIViewController = detailVC1 as UIViewController

        return [vc ,vc1  , vc ,vc1 ]
    }

and when I used a ViewController that contained a table view I get this error :

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

Error

can someone help me please ?

Wings
  • 2,398
  • 23
  • 46
Nessrine Hafi
  • 87
  • 2
  • 16
  • I think I know the problem, but I don't know the solution. Because you instantiated these view controllers yourself, rather than having them instantiated by a xib/nib/storyboard, their IBOulets have never been populated, so the tableview of one of those VCs is `nil`, for example. The solution would be to load the VCs from a storyboard, but I'm not sure how to do that, off hand. Hopefully that points you in the right direction – Alexander Aug 01 '19 at 12:22
  • yeah it make sense :) thank you very much – Nessrine Hafi Aug 01 '19 at 12:24
  • Possible duplicate of [What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?](https://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – Scriptable Aug 01 '19 at 13:26

1 Answers1

2

I initiated my ViewControllers by storyboard and it worked. so instead of :

   let detailVC = HomeViewController()
        let vc : UIViewController = detailVC as UIViewController

I wrote :

   let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let controller = storyboard.instantiateViewController(withIdentifier: "HomeViewController")

and it worked but the page is still white nothing changed. thank you Alexander

Nessrine Hafi
  • 87
  • 2
  • 16