gpt4 book ai didi

ios - PageViewController 显示黑屏

转载 作者:搜寻专家 更新时间:2023-10-31 22:43:17 25 4
gpt4 key购买 nike

在 Storyboard 中我有一个 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
}

这是我在 Storyboard中的 ReservedTimesTableViewController enter image description here

但是我遇到了黑屏。为什么它不能正常工作?

最佳答案

加载 Controller 时,您必须使用此代码设置初始页面

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
}

当您尝试滚动页面后,数据源方法将完成它们的工作。

关于ios - PageViewController 显示黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42764230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com