Code Monkey home page Code Monkey logo

Comments (3)

bhargavg avatar bhargavg commented on May 30, 2024 1

You can do it like this:

diff --git a/Example/Sources/CarouselCell.swift b/Example/Sources/CarouselCell.swift
index 576dfba..a3ca87c 100644
--- a/Example/Sources/CarouselCell.swift
+++ b/Example/Sources/CarouselCell.swift
@@ -10,9 +10,11 @@ import UIKit
 import Pickme
 
 class CarouselCell: UICollectionViewCell {
-
     @IBOutlet weak var imageView: UIImageView!
 
+    var model: UIImage!
+    weak var tapHandler: TapHandler?
+
     override func awakeFromNib() {
         backgroundColor = .lightGray
         layer.contentsScale = UIScreen.main.scale
@@ -24,6 +26,9 @@ class CarouselCell: UICollectionViewCell {
         layer.borderWidth = 1
         layer.borderColor = UIColor.white.cgColor
         clipsToBounds = true
+
+        let gesture = UITapGestureRecognizer(target: self, action: #selector(self.didTap))
+        addGestureRecognizer(gesture)
     }
 
     override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
@@ -39,4 +44,7 @@ class CarouselCell: UICollectionViewCell {
         layer.cornerRadius = bounds.height/2
     }
 
+    func didTap() {
+        tapHandler?.didTap(item: model)
+    }
 }
diff --git a/Example/Sources/CarouselPresenter.swift b/Example/Sources/CarouselPresenter.swift
index 530c56e..fcfac32 100644
--- a/Example/Sources/CarouselPresenter.swift
+++ b/Example/Sources/CarouselPresenter.swift
@@ -10,7 +10,16 @@ import UIKit
 import Pickme
 
 struct CarouselPresenter: Presenter {
+    weak var tapHandler: TapHandler?
+
+    init(tapHandler: TapHandler) {
+        self.tapHandler = tapHandler
+    }
+
     func render(cell: CarouselCell, with image: UIImage, at: IndexPath) {
         cell.imageView.image = image
+
+        cell.model = image
+        cell.tapHandler = tapHandler
     }
 }
diff --git a/Example/Sources/CarouselViewController.swift b/Example/Sources/CarouselViewController.swift
index d669ef6..e994035 100644
--- a/Example/Sources/CarouselViewController.swift
+++ b/Example/Sources/CarouselViewController.swift
@@ -23,8 +23,10 @@ final class CarouselViewController: UIViewController, Delegate {
 
     override func viewDidLoad() {
         super.viewDidLoad()
-        
-        picker = Pickme(with: collectionView, items: items, presenter: CarouselPresenter()) { config in
+
+        let presenter = CarouselPresenter(tapHandler: self)
+
+        picker = Pickme(with: collectionView, items: items, presenter: presenter) { config in
             config.itemSpacing = 10.0
             config.itemSize = CGSize(width: 100.0, height: 100.0)
             config.flowDistance = 200.0
@@ -44,3 +46,9 @@ final class CarouselViewController: UIViewController, Delegate {
         print(items[index]);
     }
 }
+
+extension CarouselViewController: TapHandler {
+    func didTap(item: UIImage) {
+        performSegue(withIdentifier: "Your Segue Identifier", sender: nil)
+    }
+}
diff --git a/Example/Sources/TapHandler.swift b/Example/Sources/TapHandler.swift
new file mode 100644
index 0000000..d4f2d99
--- /dev/null
+++ b/Example/Sources/TapHandler.swift
@@ -0,0 +1,13 @@
+//
+//  TapHandler.swift
+//  Example
+//
+//  Created by Gurlanka, Bhargav (Agoda) on 03/04/17.
+//  Copyright © 2017 Bhargav Gurlanka. All rights reserved.
+//
+
+import UIKit
+
+protocol TapHandler: class {
+    func didTap(item: UIImage)
+}

from pickme.

EriFisher avatar EriFisher commented on May 30, 2024

Wow thank you! I really appreciate you taking the time to show me.

from pickme.

bhargavg avatar bhargavg commented on May 30, 2024

Glad I could help. I'm closing this issue for now, please feel free to re-open if needed.

from pickme.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.