Chỉ cần bỏ qua điều này ở đây trong trường hợp bất kỳ ai muốn sử dụng giao thức được xác định để điều hướng và thay đổi bộ điều khiển chế độ xem theo chương trình.
@objc protocol AppWalkThroughDelegate {
@objc optional func goNextPage(forwardTo position: Int)
@objc optional func goPreviousPage(fowardTo position: Int)
}
Sử dụng giao thức ở trên và xác nhận quyền root UIPageViewController để quản lý điều hướng giữa bộ điều khiển chế độ xem.
Ví dụ dưới đây:
class AppWalkThroughViewController: UIPageViewController, UIPageViewControllerDataSource, AppWalkThroughDelegate {
// Add list of view controllers you want to load
var viewControllerList : [UIViewControllers] = {
let firstViewController = FirstViewController()
let secondViewController = SecondViewController()
// Assign root view controller as first responder
secondViewController.delegate = self
let thirdViewController = ThirdViewController()
}
override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
}
// Navigate to next page
func goNextPage(fowardTo position: Int) {
let viewController = self.viewControllerList[position]
setViewControllers([viewController], direction:
UIPageViewControllerNavigationDirection.forward, animated: true, completion: nil)
}
}
Khi đạt được tất cả những gì, nhìn con điều khiển mà cần phải thực hiện UIPageViewController chuyển sang trang tiếp theo hoặc trước đó có thể sử dụng phương pháp AppWalkThroughDelegate bằng cách thông qua một số cụ thể vào bất động sản đại biểu.
Ví dụ dưới đây: phương pháp đại biểu gọi một lần nút nhấn
class SecondViewController: UIViewController {
var delegate: AppWalkThroughDelegate!
override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
}
@IBAction func goNextPage(_ sender: Any) {
// Can be any number but not outside viewControllerList bounds
delegate.goNextPage!(fowardTo: 2)
}
}
Nguồn
2017-08-15 04:30:44
thể trùng lặp của [? Có thể Rẽ trang lập trình trong UIPageViewController] (http://stackoverflow.com/questions/7208871/is -it-can-to-turn-page-program -atic-in-uipageviewcontroller) –