我正在尝试添加一个具有多个 View Controller 的页面 Controller 。我首先在 interfacebuilder 中创建了一个 contentView 并在其中嵌入了一个 pageController。然后我添加了下面的代码,但它似乎没有显示任何内容?
let initialViewController = self.viewControllerAtIndex(0)
self.pageViewController?.setViewControllers([initialViewController], direction: .Forward, animated: false, completion: nil)
PAgeViewController 扩展
var viewControllerIdentifiers = ["BottomNoLogo", "TopNoLogo"]
extension CameraViewController: UIPageViewControllerDataSource {
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let currentText = viewController.restorationIdentifier
var currentIndex = viewControllerIdentifiers.indexOf(currentText!)
if currentIndex == viewControllerIdentifiers.count - 1 {
return viewControllerAtIndex(0)
} else {
return viewControllerAtIndex(++currentIndex!)
}
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
let currentText = viewController.restorationIdentifier
var currentIndex = viewControllerIdentifiers.indexOf(currentText!)
if currentIndex == 0 {
return viewControllerAtIndex(viewControllerIdentifiers.count - 1)
} else {
return viewControllerAtIndex(--currentIndex!)
}
}
func viewControllerAtIndex(index: Int) -> UIViewController {
let contentViewController = storyboard?.instantiateViewControllerWithIdentifier(viewControllerIdentifiers[index])
return contentViewController!
}
}
最佳答案
页面 View Controller 实际上只是提供点:您仍然必须将 Controller 的 View 添加为父 View 的 subview 并管理滚动。那里有很多例子。参见 http://www.appcoda.com/uipageviewcontroller-tutorial-intro/ ,例如。
关于ios - 具有多个 viewController 的 pageController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34502207/