JoniVR / VerticalCardSwiper

A marriage between the Shazam Discover UI and Tinder, built with UICollectionView in Swift.
MIT License
1.4k stars 101 forks source link

Delegate issue? #17

Closed richardpap closed 6 years ago

richardpap commented 6 years ago

Hey, After following the how to use section, I'm running into an error: "Type 'XYViewController' does not conform to protocol 'VerticalCardSwiperDatasource'" and wants to add the "cardForItemAt" function, however, its implemented as it was described:

func cardForItemAt(verticalCardSwiperView: VerticalCardSwiperView, cardForItemAt index: Int) -> CardCell {
        let cardCell = verticalCardSwiperView.dequeueReusableCell(withReuseIdentifier: "ExampleCell", for: index) as! ExampleCardCel
        return cardCell
    }

This function has a warning btw: "Cast from 'UICollectionViewCell' to unrelated type 'ExampleCardCell' always fails"

The only difference in my code is that i dont use storyboard, so this is how the viewDidLoad looks like:

    override func viewDidLoad() {
        super.viewDidLoad()        
        cardSwiper = VerticalCardSwiper(frame: self.view.bounds)
        cardSwiper.datasource = self
        cardSwiper.register(ExampleCardCell.self, forCellWithReuseIdentifier: "ExampleCell")
    }

I'm experience this in xCode 10 and Swift 4.2

JoniVR commented 6 years ago

Hi @richardpap,

Quick question, what does your ExampleCardCell class look like? Does it inherit from CardCell?

If it doesn't, that should explain why you get the Cast from 'UICollectionViewCell' to unrelated type 'ExampleCardCell' always fails" message.

I just removed the .nib file and did the whole cell loading programmatically in the example and that seems to work for me so I think it should work. You could try comparing these projects and seeing where yours differs.

You can find the modified (code-only cells) example version here: VerticalCardSwiper.zip

If you're still having issues after that, I'd be happy to help you out further, in that case, please let me know as many details as possible (for example what you're doing differently that could be causing this, error messages, warnings, ...)

Hope this helps.

Kinds regards, Joni

richardpap commented 6 years ago

Hmm, i created a brand new project, implemented everything by your example and now it works. So something most be in my project causing this issue.

Thank you for the help!

Kind regards, Richard

JoniVR commented 6 years ago

Any updates on this? Did you find the problem?

richardpap commented 6 years ago

Yep, I managed to fix it last night. I had a class called CardCell as well in my code, which caused the issue. Now everything works perfectly.

JoniVR commented 6 years ago

Alright, great to hear! 🎉 Closing this issue 🙂