Guest User

Untitled

a guest
Jan 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. setViewControllers([subjective], direction: .Forward, animated: true, completion: nil)
  2.  
  3. setViewControllers([firstVC], direction: .Forward, animated: true, completion: nil)
  4.  
  5. import UIKit
  6.  
  7. class PageVC : UIPageViewController, UIPageViewControllerDelegate, UIPageViewControllerDataSource {
  8.  
  9. var lblhoten = String()
  10. var lblngaysinh = String()
  11. var lblsodt = String()
  12.  
  13. lazy var VCArr: [UIViewController] = {
  14. return [self.VCInstance("ThongTinBNPage2"),
  15. self.VCInstance("ThongTinBNPage3")]
  16. }()
  17.  
  18. private func VCInstance(name: String) -> UIViewController {
  19. return UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier(name)
  20. }
  21.  
  22. override func viewDidLoad() {
  23. super.viewDidLoad()
  24. self.dataSource = self
  25. self.delegate = self
  26. if let firstVC = VCArr.first {
  27. let subjective = self.storyboard?.instantiateViewControllerWithIdentifier("ThongTinBNPage2") as! VCSubjective
  28. subjective.lblhoten = lblhoten
  29. subjective.lblngaysinh = lblngaysinh
  30. subjective.lblsodt = lblsodt
  31. setViewControllers([subjective], direction: .Forward, animated: true, completion: nil)
  32. }
  33. }
  34.  
  35. public func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
  36. guard let viewcontrollerindex = VCArr.indexOf(viewController) else {
  37. return nil
  38. }
  39.  
  40. let previousindex = viewcontrollerindex - 1
  41.  
  42.  
  43. guard previousindex >= 0 else {
  44. return VCArr.last
  45. }
  46.  
  47. guard VCArr.count > previousindex else {
  48. return nil
  49. }
  50.  
  51. return VCArr[previousindex]
  52. }
  53.  
  54. public func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
  55. guard let viewcontrollerindex = VCArr.indexOf(viewController) else {
  56. return nil
  57. }
  58.  
  59. let nextindex = viewcontrollerindex + 1
  60.  
  61.  
  62. guard nextindex < VCArr.count else {
  63. return VCArr.first
  64. }
  65.  
  66. guard VCArr.count > nextindex else {
  67. return nil
  68. }
  69.  
  70. return VCArr[nextindex]
  71. }
  72.  
  73. public func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
  74. return VCArr.count
  75. }
  76.  
  77. // The selected item reflected in the page indicator.
  78. public func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
  79. guard let firstviewcontroller = viewControllers?.first,
  80. let firstviewcontrollerindex = VCArr.indexOf(firstviewcontroller) else {
  81. return 0
  82. }
  83.  
  84. return firstviewcontrollerindex
  85. }
Add Comment
Please, Sign In to add comment