我正在与UISlider合作,我想认识到价值的变化:
var sliderGeofence: UISlider!
在我的
viewDidLoad()
中: self.sliderGeofence = UISlider(frame: CGRect(x: 20, y: 20, width: self.view.frame.size.width - 50, height: 50))
self.sliderGeofence?.maximumValue = 100000
self.sliderGeofence?.minimumValue = 500
self.sliderGeofence?.value = 100
self.sliderGeofence?.isUserInteractionEnabled=true
self.sliderGeofence?.addTarget(self, action: Selector("geofenceValueChange:"),for: UIControlEvents.valueChanged)
gmsMap.addSubview(self.sliderGeofence!)
sliderGeofence?.isHidden = true
我的值更改方法:
@IBAction func geofenceValueChange(sender: AnyObject)
{
print("entro")
}
但是,当我更改滑块的值时,应用程序会加载滑块:
***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[MocaAdmin.FirstViewController
geofenceValueChange::发送到实例的选择器无法识别
0x7fca61511480'
我做错什么了?
最佳答案
将目标更改为以下内容:
sliderDemo.addTarget(self, action: #selector(geofenceValueChange(_:)), for: .valueChanged)
然后函数:
func geofenceValueChange(_ sender:UISlider) {
print("entro")
}
不需要函数中的
@IBAction
。关于ios - 无法识别的选择器发送到实例,UISlider swfit3,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42987242/