2017-05-06 100 views
-1

我的页面控制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

代码的顶部部分似乎不完全。至少缺少一个功能。 –

+0

你在谈论collectionview吗?我不这么认为,我错过了哪个功能? –

+0

'thisWidth'到'pageControl.currentPage = 0'不包含在方法中。我只是不明白它们在文件中的位置。 –

回答

2

删除此行:

pageControl = UIPageControl.appearance() 
+0

是老实说吧!谢谢。 –

相关问题