I am creating an app in UIKit, programmatically.
One display has a UITableView with customized cells, some have sliders inside. All cells present up and might be chosen. Different customized cell parts like buttons and textual content discipline react to interplay, however not the sliders.
Here is my code:
class CellWithSliderValues: UITableViewCell{
@IBOutlet var slider: UISlider! = {
let ctrl = UISlider()
// coloration setup right here
return ctrl
}()
// some labels
override init(type: UITableViewCell.CellStyle, reuseIdentifier: String?) {
tremendous.init(type: type, reuseIdentifier: reuseIdentifier)
self.addSubview(slider);
// structure code, skipped for StackOverflow
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been carried out")
}
}
How the cell is created for the desk, with tag calculation skipped:
let cell = mainScreen.desk.dequeueReusableCell(withIdentifier: "CellWithSliderValues") as! CellWithSliderValues
cell.slider.maximumValue = Constants.BEST
cell.slider.minimumValue = Constants.WORST
cell.slider.worth = currvalue
// tag is ready right here
cell.slider.addTarget(self, motion: #selector(sliderChange), for: .valueChanged)
return cell
A part of the delegate that is named when clicking of the slider cell:
guard let cell = (mainScreen.desk.cellForRow(at: indexPath) as? CellWithSliderValues) else {return}
cell.slider.becomeFirstResponder()
return
Lastly, the operate that needs to be referred to as when the slider is dragged however is rarely really referred to as (seen with breakpoints):
@objc func sliderChange(sender: UISlider){
// get the values right here
sender.resignFirstResponder()
}
The identical strategy did work with the textual content entry fields, so what am i doing fallacious right here? Is it due to the Slider not having delegates?