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

Invoke custom action #49

Closed
flypaper0 opened this issue Mar 29, 2017 · 1 comment
Closed

Invoke custom action #49

flypaper0 opened this issue Mar 29, 2017 · 1 comment

Comments

@flypaper0
Copy link

How can I invoke in cell custom action? For example I have viewController with
func presentScreen() { let viewController = ViewController() present(viewController, animated: true, completion: nil) }

and want to call this method on tap a button from cell

@DenTelezhkin
Copy link
Owner

You can subscribe to button tap for example in configureCell Event, something like this:

manager.configure(MyCell.self) { cell, model, indexPath in
   // subscribe for button tap
}

Remember that you need to unsubscribe in prepareForReuse or events will be duplicated. One useful pattern i found for myself is use RxSwift, subscribe to tap and make a DisposeBag, which disposes in prepareForReuse method, like so:

manager.configure(MyCell.self) { cell, model, indexPath in
     cell.button.rx.tap.asDriver().drive(onNext: { [weak self] in
        self?.presentScreen()
     }).disposed(by: cell.reuseDisposeBag)
}

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

No branches or pull requests

2 participants