Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setViewControllers([subjective], direction: .Forward, animated: true, completion: nil)
- setViewControllers([firstVC], direction: .Forward, animated: true, completion: nil)
- import UIKit
- class PageVC : UIPageViewController, UIPageViewControllerDelegate, UIPageViewControllerDataSource {
- var lblhoten = String()
- var lblngaysinh = String()
- var lblsodt = String()
- lazy var VCArr: [UIViewController] = {
- return [self.VCInstance("ThongTinBNPage2"),
- self.VCInstance("ThongTinBNPage3")]
- }()
- private func VCInstance(name: String) -> UIViewController {
- return UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier(name)
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- self.dataSource = self
- self.delegate = self
- if let firstVC = VCArr.first {
- let subjective = self.storyboard?.instantiateViewControllerWithIdentifier("ThongTinBNPage2") as! VCSubjective
- subjective.lblhoten = lblhoten
- subjective.lblngaysinh = lblngaysinh
- subjective.lblsodt = lblsodt
- setViewControllers([subjective], direction: .Forward, animated: true, completion: nil)
- }
- }
- public func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
- guard let viewcontrollerindex = VCArr.indexOf(viewController) else {
- return nil
- }
- let previousindex = viewcontrollerindex - 1
- guard previousindex >= 0 else {
- return VCArr.last
- }
- guard VCArr.count > previousindex else {
- return nil
- }
- return VCArr[previousindex]
- }
- public func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
- guard let viewcontrollerindex = VCArr.indexOf(viewController) else {
- return nil
- }
- let nextindex = viewcontrollerindex + 1
- guard nextindex < VCArr.count else {
- return VCArr.first
- }
- guard VCArr.count > nextindex else {
- return nil
- }
- return VCArr[nextindex]
- }
- public func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
- return VCArr.count
- }
- // The selected item reflected in the page indicator.
- public func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
- guard let firstviewcontroller = viewControllers?.first,
- let firstviewcontrollerindex = VCArr.indexOf(firstviewcontroller) else {
- return 0
- }
- return firstviewcontrollerindex
- }
Add Comment
Please, Sign In to add comment