PageViewController 显示黑屏
PageViewController showing a black screen
在故事板中我有一个 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
但我遇到了黑屏。为什么它不能正常工作?
加载控制器时,您必须使用此代码设置初始页面
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
}
当您尝试滚动页面后,数据源方法将完成它们的工作。
在故事板中我有一个 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
但我遇到了黑屏。为什么它不能正常工作?
加载控制器时,您必须使用此代码设置初始页面
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
}
当您尝试滚动页面后,数据源方法将完成它们的工作。