issue while changing the CurrentPage of UIPageControl which is Inside a TableViewCell

末鹿安然 提交于 2019-12-12 10:26:12

问题


am trying to create a Carousel inside tableViewCell and am almost there but am having difficulty while implementing the UIPageControl in my TableView so that when CollectionViewCell's (which is inside tableViewCell) Item got changed i can show it on UIPageControl,

i tried the below solution and encountered a strange behaviour (maybe its strange for only me ) , when the View Loads and i change my item (which is in collectionViewCell) the PageControl's currentPage is not changing but after scrolling down to the end of tableView and coming back to top its working fine ,

suppose you have 6 rows and you scroll down to row 6 and then when you scroll up to row 5 and change its item the pageControl will work , if you keep doing this until reaching the top it'll going to work fine but if you go from row 5 to 6 and change row 6's item then its not going to work

i am initialising my pageControl in cellForRowAtIndexPath :

  pagerControll = cell.pageControll

then trying to change the position by listening to ScrollView's 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) }
}

any idea why this is happening ?? or how to fix this ??

P.s if question is not clear enough then let me know , i'll add some more detail

UPDATE:

when view loads and am changing the item of collectionViewCell the below cell's pageControl's currentPage is Changing


回答1:


after getting pissed off , WE MADE IT

    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
            }
        }

    }



来源:https://stackoverflow.com/questions/37883572/issue-while-changing-the-currentpage-of-uipagecontrol-which-is-inside-a-tablevie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!