ios - swift/iOS8 : Why are Page Control indicators not showing?

标签 ios swift uipageviewcontroller uipagecontrol

我正在实现一个简单的画廊 View Controller ,其中应用程序显示用户可以滚动浏览的小范围全屏图像。我正在使用我认为的 UIPageViewController,如果我实现了正确的数据源功能,它应该会自动显示页面控制指示器。但是我仍然看不到任何指标。

在我的主要 GalleryViewController 中:

class GalleryViewController: UIViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {

var pageController: UIPageViewController?
var pageContent = NSArray()

override func viewDidLoad() {
super.viewDidLoad()
.... some code to load images into the pageContent array ....

pageController = UIPageViewController(transitionStyle:.Scroll, navigationOrientation:.Horizontal,options:nil) 
pageController?.delegate = self
pageController?.dataSource = self

... some more standard code to add the page controller to self.view etc.

var pageControl = UIPageControl.appearance()
pageControl.pageIndicatorTintColor = UIColor.lightGray()
pageControl.currentPageIndicatorTintColor = UIColor.whiteColor()
pageControl.backgroundColor = UIColor.blackColor()

pageController!.didMoveToParentViewController(self)
}

func viewControllerAtIndex(index:Int) -> ContentViewController? {
....
}

我已经实现了两个强制性协议(protocol)方法 viewControllerBeforeViewController 和 viewControllerAfterController 以及分页所需的两个方法 presentationCountForPagesViewController 和 presentationIndexForPageViewController。

我的 ContentViewController 有一个充满整个屏幕的 UIImageView。然而,即使我将它的尺寸从屏幕底部缩小,我也看不到任何页面指示灯。 我在这里错过了什么吗?如果我没有提供足够的信息,请告诉我。我一直在尝试重写我 5 年前用 Objective-C 编写的一个旧应用程序——完全用 Swift 为 iOS8 和 Xcode 等编写。变化太大了,令人困惑。 谢谢!

最佳答案

取自here :

In order to show UIPageControl, you need to implement two optional datasource methods. Just return the whole number of pages for presentationCountForPageViewController and the initially selected index for presentationIndexForPageViewController

func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
    return pageContent.count
}

func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
    return 0
}

关于ios - swift/iOS8 : Why are Page Control indicators not showing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30943075/

相关文章:

ios - 返回 Result<Object> 时,Realmswift 通用函数调用崩溃

ios - 根据缩放级别缩放自定义标记图标

ios - 哪个 Xcode 对象用于显示从 SQL 语句中获取的简单表?

swift - 自定义表格 View

objective-c - 带有渐变叠加的 UIPageViewController?

ios - 如何将c程序转换为完全可移植的ios

iphone - 追踪 iOS 内存峰值

ios - 存储空间已满时将应用程序数据保存到用户的 iCloud(CloudKit)?

ios - UIpageviewcontroller 内的 UIScrollview

swift - 添加为 subview 时 UIPageViewController 无法识别滑动