PageViewController 显示黑屏
Posted
技术标签:
【中文标题】PageViewController 显示黑屏【英文标题】:PageViewController showing a black screen 【发布时间】:2017-03-13 12:56:59 【问题描述】:在故事板中我有一个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
但我遇到了黑屏。为什么它不能正常工作?
【问题讨论】:
检查是否为页面控制器设置了委托和数据源 你为什么用UITableViewController
作为UIPageViewController
【参考方案1】:
在加载控制器时,您必须使用此代码设置初始页面
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
当您尝试滚动页面后,数据源方法将完成它们的工作。
【讨论】:
以上是关于PageViewController 显示黑屏的主要内容,如果未能解决你的问题,请参考以下文章
IOS:通过PageViewController显示WebView
如何让 PageViewController 显示不同的 ViewController
嵌入在 containerView 中的 PageViewController 显示前一个视图的小边距