在故事板中,我有一个UIPageViewController
,这是我的代码
class ReservedTimesViewController: UIPageViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
extension ReservedTimesViewController: UIPageViewControllerDataSource {
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ReservedTimesTableViewController")
print(controller)
return controller
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ReservedTimesTableViewController")
print(controller)
return controller
}
这是故事板中的ReservedTimesTableViewController
但是我的黑屏。为什么它不能正常工作?
答案 0 :(得分:2)
加载控制器时,您必须使用此代码
设置初始页面override func viewDidLoad() {
super.viewDidLoad()
dataSource = self;
self.setViewControllers([getViewControllerAtIndex(index: 0)] as [UIViewController], direction: UIPageViewControllerNavigationDirection.forward, animated: false, completion: nil)
}
func getViewControllerAtIndex(index: Int) -> ReservedTimesTableViewController
{
// Create a new view controller and pass suitable data.
let reservedTimesTableViewController = self.storyboard?.instantiateViewController(withIdentifier: "ReservedTimesTableViewController") as! ReservedTimesTableViewController
return reservedTimesTableViewController
}
当您尝试滚动页面后,数据源方法将完成其工作。