IOS UIPageViewController第二个视图没有加载

时间:2015-11-15 21:27:11

标签: ios swift uipageviewcontroller

我的PageViewController有问题。当我通过点击页面指示器来切换视图时它按预期工作,但是当我每次滑动时,每次扫描都是空白(黑色)。滑动时的预览显示正确,但是当我完成滑动时,视图消失。

import UIKit

class ScheduleViewController: UIViewController,  UIPageViewControllerDataSource, UIPageViewControllerDelegate {

@IBAction func editButton(sender: AnyObject) {
    (self.pageViewController.view as! UITableView).setEditing(true, animated: true)
    print((self.pageViewController.view as! UITableView).editing)
}
 @IBOutlet weak var navBar: UINavigationItem!
var pageViewController: UIPageViewController!
var index = 0
var viewControllers: [ContentViewController] = []
override func viewDidLoad()
{
    self.navigationController!.navigationBar.translucent = false
    self.tabBarController!.tabBar.translucent = false


    self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ScheduleViewControllerPage") as! UIPageViewController
    self.pageViewController.dataSource = self
    self.pageViewController.delegate = self
    for a in [0,1,2,3,4]{
    var vc: ContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ContentViewController") as! ContentViewController
        vc.pageIndex = a
        vc.tableView.reloadData()
        self.viewControllers.append(vc)
    }
    print(viewControllers)
    self.pageViewController.setViewControllers([self.viewControllers[0]] as [UIViewController], direction: .Forward, animated: false, completion: nil)

    self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.size.height)
    self.addChildViewController(self.pageViewController)
    self.view.addSubview(self.pageViewController.view)
    self.pageViewController.didMoveToParentViewController(self)
    super.viewDidLoad()

}



override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}




func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?
{
    index--
    if index <= -1 {
        index = 4
    }
    return self.viewControllers[index] as UIViewController


}

func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
    index++
    if index >= 5 {
        index = 0
    }
    return self.viewControllers[index] as UIViewController

}

func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int
{
    return 5
}

func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int
{
    return index
}

}

0 个答案:

没有答案