更改位于 TableViewCell 内的 UIPageControl 的 CurrentPage 时出现问题
issue while changing the CurrentPage of UIPageControl which is Inside a TableViewCell
我正在尝试在 tableViewCell 中创建一个 Carousel,我几乎就在那里,但是在我的 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 正在更改
生气之后,我们做到了
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 中创建一个 Carousel,我几乎就在那里,但是在我的 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 正在更改
生气之后,我们做到了
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
}
}
}