我的UIPageViewController在运行时显示为黑屏。
它是app delegage中设置的根视图控制器:
window = UIWindow()
let mainPageViewController = MainPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
window?.rootViewController = mainPageViewController
这是我的MainPageViewController代码:
class MainPageViewController: UIPageViewController, UIPageViewControllerDataSource
{
override func viewDidLoad()
{
super.viewDidLoad()
dataSource = self
let profileController = ProfileController()
let viewControllers = [profileController]
self.setViewControllers(viewControllers, direction: .forward, animated: true, completion: nil)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?
{
return nil
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?
{
return nil
}
}
我试图设置为初始页面的profilecontroller是普通的UIViewController。
我已经尝试了很多东西,但它总是显示黑屏。关于我做错了什么的任何想法?
答案 0 :(得分:1)
试试这个: -
self.window = UIWindow(frame: UIScreen.main.bounds)
let mainPageViewController = MainPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
window?.rootViewController = mainPageViewController
self.window?.makeKeyAndVisible()
答案 1 :(得分:1)
你的PageViewController非常好。然而,您设置rootViewController的过程错过了以下内容:
window = UIWindow()
let mainPageViewController = MainPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
window?.rootViewController = mainPageViewController
// This line will make it visible
window?.makeKeyAndVisible()
答案 2 :(得分:0)
我无法确定您的问题是什么,如果您的问题是you don't know why your screen is black?
,我认为您应该在appDelegate中设置:
window.backgroundColor = .white
这是你的控制器:
self.view.backgroundColor = .white