【问题标题】:issue while changing the CurrentPage of UIPageControl which is Inside a TableViewCell更改 TableViewCell 内的 UIPageControl 的 CurrentPage 时出现问题
【发布时间】:2016-06-17 14:00:50
【问题描述】:

我正在尝试在 tableViewCell 内创建一个轮播,并且快到了,但是在我的 TableView 中实现 UIPageControl 时遇到了困难,因此当 CollectionViewCell(在 tableViewCell 内)的项目发生更改时,我可以在 UIPageControl 上显示它,

我尝试了下面的解决方案并遇到了一个奇怪的行为(也许它对我来说很奇怪),当视图加载并且我更改我的 item(在 collectionViewCell 中)时,PageControl 的 currentPage 没有改变,但在向下滚动到结束 tableView 并回到顶部,工作正常,

假设您有 6 行并且向下滚动到第 6 行,然后当您向上滚动到第 5 行并更改其项目时 pageControl 将起作用,如果您继续这样做直到到达顶部它会正常工作但是如果您从第 5 行转到第 6 行并更改第 6 行的项目,那么它不会工作

我正在cellForRowAtIndexPath 中初始化我的pageControl

  pagerControll = cell.pageControll

然后尝试通过监听 ScrollView 的 contentOffSet 来改变位置

override func scrollViewDidEndDecelerating(scrollView: UIScrollView) {

if scrollView != tableView {

    if scrollView.contentOffset.x >= self.view.frame.size.width && scrollView.contentOffset.x < (self.view.frame.size.width * 2){

        pagerControll.currentPage = 1
    }else if  scrollView.contentOffset.x >= (self.view.frame.size.width * 2 )  {
        pagerControll.currentPage = 2

    }else {

        pagerControll.currentPage = 0
    }

    print(scrollView.contentOffset) }
}

知道为什么会这样吗?或者如何解决这个问题?

P.s 如果问题不够清楚,请告诉我,我会添加更多细节

更新:

当视图加载并更改 collectionViewCell 的项目时,下面单元格的 pageControl 的 currentPage 正在更改

【问题讨论】:

    标签: ios swift swift2 uicollectionview uipagecontrol


    【解决方案1】:

    在生气之后,我们做到了

        override func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
    
            if scrollView != tableView {
    
               let currentCells =  tableView.visibleCells
                let cell = currentCells[0] as! NotesTableViewCell
    
                if scrollView.contentOffset.x >= self.view.frame.size.width && scrollView.contentOffset.x < (self.view.frame.size.width * 2){
    
                    cell.pageControll.currentPage = 1
                }else if  scrollView.contentOffset.x >= (self.view.frame.size.width * 2 )  {
    
                    cell.pageControll.currentPage = 2
    
                }else {
    
                    cell.pageControll.currentPage = 0
                }
            }
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-27
      • 1970-01-01
      • 2016-01-25
      • 2011-08-23
      • 2015-08-26
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多