I want to pass data from a UIPageViewController
to one of its child ViewControllers
.
I have a protocol set like so:
protocol Delegate : class{
func protocolMethod(count:Int)
}
And in UIPageViewController
:
class PageVC : UIPageViewController{
var delegate : Delegate?
var count : Int = 1
func classMethod(){
self.displayPageForIndex(5) //this controlls the tranistion to the child ViewController
self.delegate?.protocolMethod(count : self.count)
}
}
In the conforming child ViewController
:
class ChildVC : UIViewController , Delegate{
func protocolMethod(count : Int){
print(count)
}
override func viewDidLoad() {
super.viewDidLoad()
let pvc = PageVC()
pvc.delegate = self
}
}
What I've done in viewDidLoad
is the most simplistic solution I've tried, but still couldn't find the answer as to how to let the PageViewController
know that the child ViewController
is the receiver of the protocol method.
If anyone could help me accomplish that without using prepareForSegue (as there are no segues) it would be very much appreciated.