UITapGestureRecogniser 添加目标不起作用

UITapGestureRecogniser add target not working

我有一个 objc 函数:

@objc private func segmentedControlViewTapped(gestureRecognizer: UITapGestureRecognizer)

我正在尝试将其添加为 gestureRecognizer 的目标,但是当我点击分段控件时代码一直崩溃。

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

崩溃原因:发送了无法识别的选择器

该操作需要指向您指定的目标中的函数。

假设 segmentedControlViewTapped 在您的视图或控制器中,请像这样更改您的代码:

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