You are right, the recognizer should not be added to the XIB at the top level.
My decision:
class SettingsUserAvatarHeader: UITableViewHeaderFooterView {
In doing so, you can listen to the taps directly. I am using RxSwift:
First add the extension for the tap:
extension Reactive where Base: SettingsUserAvatarHeader { var avatarTap: ControlEvent<UITapGestureRecognizer> { return self.base.tapGestureRecognizer.rx.event.asControlEvent() } }
And in your controller / delegation, etc .:
class Consumer: UITableViewDelegate { var avatarTapDisposable: Disposable? override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let cell = tableView.dequeueReusableHeaderFooterView(withIdentifier: "userAvatarView") let view = cell as! SettingsUserAvatarHeader avatarTapDisposable = view.rx .avatarTap .subscribe(onNext: { (tap) in
source share