Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate items #2

Closed
fnk0 opened this issue Oct 13, 2015 · 5 comments
Closed

Duplicate items #2

fnk0 opened this issue Oct 13, 2015 · 5 comments
Labels

Comments

@fnk0
Copy link

fnk0 commented Oct 13, 2015

So.. What I want is a PagingView with 2 images. Without infinite scrolling.

I followed your example and made ImagePagingCell extending PagingViewCell (basically just a UIImageView that fills the entire nib like the one in your demo). But the problem is that instead of only having 2 images I have 4, the 2 images duplicated.

Here's some code:

// Inside viewDidLoad
self.pagingView.dataSource = self
self.pagingView.delegate = self
self.pagingView.infinite = false

// then...
func pagingView(pagingView: PagingView, numberOfItemsInSection section: Int) -> Int {
   return 2
}   

func pagingView(pagingView: PagingView, cellForItemAtIndexPath indexPath: NSIndexPath) -> PagingViewCell {
       pageControl.currentPage = indexPath.row
       let cell = pagingView.dequeueReusableCellWithReuseIdentifier("ImagePagingViewCell")
       var url : String = ""
       if indexPath.row == 0 {
          url = (self.data?.img0)!
       } else if indexPath.row == 1 {
           url = (self.data?.img1)!
       }
       let imageURL = NSURL(string: "\(Const.URL_BASE_IMAGE)\(url)")
       if let cell = cell as? ImagePageViewCell {
           cell.imageView.af_setImageWithURL(imageURL!)
       }
       return cell
}

Any ideas why I'm getting 4 pages instead of 2?

Thanks

@KyoheiG3
Copy link
Owner

How about the following:

func pagingView(pagingView: PagingView, numberOfItemsInSection section: Int) -> Int {
    return 4
}

func pagingView(pagingView: PagingView, cellForItemAtIndexPath indexPath: NSIndexPath) -> PagingViewCell {
    pageControl.currentPage = indexPath.row
    let cell = pagingView.dequeueReusableCellWithReuseIdentifier("ImagePagingViewCell")
    var url : String = ""
    if indexPath.row % 2 == 0 {
        url = (self.data?.img0)!
    } else if indexPath.row % 2 == 1 {
        url = (self.data?.img1)!
    }
    let imageURL = NSURL(string: "\(Const.URL_BASE_IMAGE)\(url)")
    if let cell = cell as? ImagePageViewCell {
        cell.imageView.af_setImageWithURL(imageURL!)
    }
    return cell
}

@fnk0
Copy link
Author

fnk0 commented Oct 14, 2015

I think you misunderstood what I'm asking... I only want 2 images. But for some reason I'm getting those 2 images duplicated giving me 4 images...

It's been driving me insane since I'm specifying numberOfItemsInSection to 2 but I'm getting 4 for some reason :(

@KyoheiG3
Copy link
Owner

I'm sorry. I misunderstood.

All of the Cell is case of two or less, bug occurs.

@KyoheiG3 KyoheiG3 added the bug label Oct 14, 2015
@rad182
Copy link
Contributor

rad182 commented Nov 20, 2015

did some workarounds. not sure if this is okay.
#7
@KyoheiG3

@KyoheiG3
Copy link
Owner

FIx in 0.4.2.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants