更改TableViewCell内部的UIPageControl的CurrentPage时出现问题 [英] issue while changing the CurrentPage of UIPageControl which is Inside a TableViewCell

查看:182
本文介绍了更改TableViewCell内部的UIPageControl的CurrentPage时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在tableViewCell中创建一个旋转木马,并且快要摆在那里了,但是在实现TableView中的UIPageControl时遇到了困难,因此当CollectionViewCell(位于tableViewCell内)的项目更改时,我可以在UIPageControl上显示它,

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,

我尝试了以下解决方案,并遇到了一个奇怪的行为(也许对我来说这很奇怪),当视图加载并且我更改了我的item(位于collectionViewCell中)时,PageControl的currentPage并未更改,但向下滚动到在tableView的末尾,回到工作正常的状态,

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 ,

假设您有6行,​​然后向下滚动至第6行,然后向上滚动至第5行并更改其项目,则pageControl将正常工作,如果您一直这样做直到到达顶部,它将可以正常工作,但是如果您从第5行转到第6行,然后将第6行的项目更改为无效,则

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

我正在cellForRowAtIndexPath中初始化我的pageControl:

  pagerControll = cell.pageControll

然后尝试通过侦听ScrollView的contentOffSet来更改位置

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

更新:

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

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

推荐答案

在生气之后,我们做到了

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

    }

这篇关于更改TableViewCell内部的UIPageControl的CurrentPage时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆