我创建了一个滑块和一个文本标签来显示滑块的值。两者都以编程方式完成:
np.logical_xor
在我的tableview中我调用函数来改变滑块的值:
class FilterCell: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let slider : UISlider = {
let slider = UISlider()
slider.minimumValue = 0
slider.maximumValue = 50
slider.value = 50
slider.continuous = true
slider.userInteractionEnabled = true
slider.translatesAutoresizingMaskIntoConstraints = false
return slider
}()
var distanceLabel : UILabel = {
let label = UILabel()
label.text = "Distance: 50km"
label.font = UIFont.systemFontOfSize(15.0)
label.textColor = UIColor.blackColor()
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
func sliderChanged(sender: UISlider) {
var sliderValue = sender.value
distanceLabel.text = "Distance: \(sliderValue)km"
}
}
滑块和标签显示正常。当我与滑块交互以更改值时,它会崩溃并且' sliderChanged:]:无法识别的选择器发送到实例0x7fb06d0df040'。
答案 0 :(得分:2)
尝试将目标添加到cell
,而不是self
cell.slider.addTarget(cell, action: #selector(FilterCell.sliderChanged(_:)), forControlEvents: .ValueChanged)