PaoloCuscela / Cards

Awesome iOS 11 appstore cards in swift 5.
MIT License
4.21k stars 275 forks source link

Cards DetailView not showing up correctly when using with UICollectionView #38

Closed seongki1 closed 6 years ago

seongki1 commented 6 years ago

Hello, I am making UI just like iOS11 app store, using Cards and Detailview with UICollectionView. I 've tried like the attached file, But..

It shows the DetailView well first a few tapping, but after loading and dismissing a few times the detailviews with swiping the collectionviewcells, the detailview does not show up correctly. I guess indexPaths are being messed up after that. And maybe it's concerned with the dequeueReusableCell..

Please check my code. Thanks a lot. CardDemo.zip

mteera commented 6 years ago

I have the same issue when it comes to tableViews as well :(

PaoloCuscela commented 6 years ago

The problem was that the card did not layout when the title label text is set. I'll fix that in the next update.

To solve this just call "layout()" after title is set:


/**
     Text of the title label.
     */
    @IBInspectable public var title: String = "The Art of the Impossible" {
        didSet{
            titleLbl.text = title
            *** layout() ***
        }
    }

CardDemo.zip

seongki1 commented 6 years ago

Thank you so much for the reply. But sadly, I think the problem does not seem to be solved yet. The cards are okay, but the detailview does not show up correctly - not showing the label and the x button either.

screen shot 2018-02-11 at 12 33 14 am screen shot 2018-02-11 at 12 32 22 am

The former is normal, and the latter has the issue. Thanks a lot.

PaoloCuscela commented 6 years ago

The x button should be hidden when the scroll view is at the top, fixed that. It took me a bit to find out, but the problem of the label was that the card in the cell was being reused and the DetailViewController(of the card's repo) was messing everything up.

Now a new detailVC is instantiated every time shouldPresent() is called


fileprivate var detailVC: DetailViewController!

public func shouldPresent( _ contentViewController: UIViewController?, from superVC: UIViewController?, fullscreen: Bool = false) {
        if let content = contentViewController {

            detailVC = DetailViewController()
            detailVC.transitioningDelegate = self

            self.superVC = superVC
            detailVC.addChildViewController(content)
            detailVC.detailView = content.view
            detailVC.card = self
            detailVC.delegate = self.delegate
            detailVC.isFullscreen = fullscreen
        }
    }

For the button just do:

xButton.alpha = 0

in DetailViewController's viewDidLoad()

CardDemo 2.zip

seongki1 commented 6 years ago

Thank you so much for the quickest fix. It works now, like a charm! You are So Genius😉 Have a nice weekend!

SahilDhawan commented 6 years ago

Card Detail View Controller not working while using FSPagerView (https://github.com/WenchaoD/FSPagerView)