1

i have a objc function:

@objc private func segmentedControlViewTapped(gestureRecognizer: UITapGestureRecognizer)

I am trying to add this as a target for a gestureRecognizer but the code keeps crashing when i tap the segment control.

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(SegmentedControl.segmentedControlViewTapped(gestureRecognizer:)))

crashes due to: unrecognized selector sent

user2512523
  • 1,229
  • 2
  • 15
  • 25

1 Answers1

1

The action needs to point to a function in the target you specified.

Assuming the segmentedControlViewTapped is in your view or controller, change your code like this:

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(segmentedControlViewTapped(gestureRecognizer:)))
ahbou
  • 4,710
  • 23
  • 36