问题
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