EZSwipeController icon indicating copy to clipboard operation
EZSwipeController copied to clipboard

calling moveToPage from another View Controller

Open Jmandarino opened this issue 6 years ago • 3 comments

When I try to call moveToPage from another class it fails on this line:

let currentIndex = stackPageVC.index(of: currentStackVC)!

with the error:

fatal error: unexpectedly found nil while unwrapping an Optional value

here is my code:

//View controller where the call is started
@IBAction func buttonRightView(_ sender: Any) {
        let vc:ViewController = storyboard?.instantiateViewController(withIdentifier: "ViewController") as! ViewController
        vc.goRight()
    }

class ViewController: EZSwipeController {
    override func setupView() {
        datasource = self
        navigationBarShouldNotExist = true
    }
    func goRight(){
        moveToPage(1, animated: true)
    }
}

Jmandarino avatar Jul 25 '17 17:07 Jmandarino

You can't do that because setupView hasn't been called on the instantiated view controller.

You need to call vc.goRight() after you set your datasource.

patthehuman avatar Sep 10 '17 18:09 patthehuman

so what is the solution here?

jaksatomovic avatar Oct 22 '17 18:10 jaksatomovic

@jaksatomovic I put this project on the back burner. I will check to see if this solves the problem in the next week

Edit: looked at this issue. I am still not sure of the solution. My goal is to reference the view controller and my method seems to be creating an entirely new reference of the "ViewController" class.

I tried modifing the view controller where the button is pressed:

//View controller where the call is started
@IBAction func buttonRightView(_ sender: Any) {
        let vc:ViewController = storyboard?.instantiateViewController(withIdentifier: "ViewController") as! ViewController
        //added lined
       vc.setupView()
        vc.goRight()
    }

However this gives me error in the moveToPage function. @patthehuman Do you have any advice?

Jmandarino avatar Oct 24 '17 14:10 Jmandarino