我的页面控制UI未获得更新。页面控件号每次都会更新,但在页面控制UI中没有更新。我想也许使用updateCurrentPageDisplay会工作,或者那是我所缺少的,但我刚刚收到错误。这是我的代码。我错过了更新用户界面需要的东西吗?
@IBOutlet weak var pageControl: UIPageControl!
override func viewDidLoad() {
super.viewDidLoad()
collection.delegate = self
collection.dataSource = self
thisWidth = CGFloat(collection.frame.width)
pageControl.hidesForSinglePage = true
pageControl = UIPageControl.appearance()
pageControl.pageIndicatorTintColor = UIColor.lightGray
pageControl.currentPageIndicatorTintColor = UIColor.red
pageControl.numberOfPages = 10
pageControl.currentPage = 0
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CalanderCollectionViewCell
let imagePath = array[indexPath.section]
cell.configureCell(properties: imagePath)
return cell
}
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
self.pageControl.currentPage = indexPath.section
print("current page\(pageControl.currentPage)")
pageControl.updateCurrentPageDisplay()
print(indexPath.section)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
thisWidth = CGFloat(collection.frame.width)
return CGSize(width: thisWidth, height: collection.frame.height)
}
答案 0 :(得分:3)
删除此行:
pageControl = UIPageControl.appearance()