EZSwipeController
EZSwipeController copied to clipboard
calling moveToPage from another View Controller
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)
}
}
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.
so what is the solution here?
@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?