I have a UIPageViewController that contains 4 view controllers
I set a timer to automatically change the view controllers (go to the next view controllers). This timer and method will work. But the problem is that it works. Only for the first slide and when the application starts, and after 5 seconds the UIPageViewController will show the second slide, but nothing will happen after that! This is the code I used
lazy var VCArr : [UIViewController] = { return [self.VCInstance(name : "VC1"), self.VCInstance(name : "VC2"), self.VCInstance(name :"VC3"), self.VCInstance(name :"VC4")] }() func changeSlide() { print("Slide Change!") guard let currentViewController = self.VCArr.first else { return } guard let nextViewController = dataSource?.pageViewController( self, viewControllerAfter: currentViewController ) else { return } setViewControllers([nextViewController], direction: .forward, animated: true, completion: nil) } var tTime: Timer! override func viewDidLoad() { super.viewDidLoad() tTime = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(changeSlide), userInfo: nil, repeats: true) }
I think the problem is in this line
guard let currentViewController = self.VCArr.first else { return }
But I do not know how to change this line to work fine
ios timer uiviewcontroller swift3 uipageviewcontroller
Saeed rahmatolahi
source share