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

Reusable issue with UITableView #43

Open
RaghavaNaidu46 opened this issue Mar 16, 2018 · 5 comments
Open

Reusable issue with UITableView #43

RaghavaNaidu46 opened this issue Mar 16, 2018 · 5 comments
Labels

Comments

@RaghavaNaidu46
Copy link

RaghavaNaidu46 commented Mar 16, 2018

I would like to thank you for the great work.
When we tap on the card you are creating an instance of DetailViewController along with Chaildviewcontroller. when we come out of that screen, you are keeping the view instance in the stack. kindly tell me the solution for this. I'm attaching my sample project in the attachments. kindly look into it as well.

Thanks in advance.
AppStoreCardView.zip

@PaoloCuscela
Copy link
Owner

the detailViewController you provide in 'shouldPresent' get saved in the card instance because otherwise every time the card get opened I should ask for a new detailViewController to be provided.
I'm now fixing some minor bug but I'm considering to redesign the framework to accept a delegate asking for a new detailvc for each opening of the card.

@RaghavaNaidu46
Copy link
Author

That's a great idea. Meanwhile, if you have any sample project on UITableView, Kindly drop here, please.
Thanks.

@asikand-view
Copy link

asikand-view commented Jun 19, 2018

I edited the shouldPresent method as follows

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

Comment out the detailVC private variable and add a fullscreenEnabled variable:
//fileprivate var detailVC = DetailViewController()
var fullscreenEnabled = false

Create and setup the contentViewController and DetailViewController on the spot instead of storing as a variable

@objc func cardTapped() {

        self.delegate?.cardDidTapInside?(card: self)
        
        //Just create the cardContentVC on the spot, just a test View Controller
        let cardContentVC = UIViewController()
        let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
        label.center = CGPoint(x: 160, y: 285)
        label.textAlignment = .center
        label.text = "I am a test label"
        label.textColor = UIColor.black
        cardContentVC.view.addSubview(label)
        
        
        //Create and setup the detailVC, this happens every time the Card is tapped now
        let content = cardContentVC
        let detailVC = DetailViewController()
        detailVC.transitioningDelegate = self
        detailVC.addChildViewController(content)
        detailVC.detailView = content.view
        detailVC.delegate = self.delegate
        detailVC.isFullscreen = fullscreenEnabled
        detailVC.transitioningDelegate = self
        detailVC.card = self
        
        //Just like normal, we present the detailVC that is now fully configured
        if let vc = superVC {
            vc.present(detailVC, animated: true, completion: nil)
        } else {
            
            resetAnimated()
        }
    }

Proposed Better Solution
Create a delegate method called contentViewForCard


@objc func cardTapped() {

        self.delegate?.cardDidTapInside?(card: self)

        let content = self.delegate?.contentViewControllerForCard?(card: self)

        let detailVC = DetailViewController()
        detailVC.transitioningDelegate = self
        detailVC.addChildViewController(content)
        detailVC.detailView = content.view
        detailVC.delegate = self.delegate
        detailVC.isFullscreen = fullscreenEnabled
        detailVC.transitioningDelegate = self
        detailVC.card = self
      
        if let vc = superVC {
            vc.present(detailVC, animated: true, completion: nil)
        } else {
            
            resetAnimated()
        }
    }

@PaoloCuscela
Copy link
Owner

That seems a good solution, could you open a PR so I can test it out ? :)

@asikand-view
Copy link

asikand-view commented Jun 25, 2018

Sure, I'll open one today. I have been using this method and it has been working but the only issue is that I am presenting a Web View (WKWebView) in each Detail View Controller. By utilizing this delegate method, I successfully avoid the Web View somehow becoming stale and not presenting any content like in @53, but it has to reload the page every time the card is reopened which often takes some time. Unfortunately WKWebView does its own caching so not sure how to cache the Web Content and prevent it from reloading each time...

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