fandro fandro - 2 years ago 163
iOS Question

UISlider long touch to move it in a UITableView

I have a uitableview with multiples custom cells, the problem is that the UISlider in one of my customs cell, is slow I need to press it about half a second to be able to move it I supposed that I can use the

to solve the problem but I m not sure if t's the solution, how to implement ? I supposed it's a problem of focus because I tried to do a simple project a uitableview with 20 sliders and it works perfectly. How can I solve the problem ?

Here is my code :
For the UITableView
method :

let cell = tableView.dequeueReusableCellWithIdentifier(CurrentFormTableView.CellIdentifiers.SliderCell, forIndexPath: indexPath) as! SliderCell
cell.delegate = self
cell.slider.tag = indexPath.row
cell.selectionStyle = UITableViewCellSelectionStyle.None
return cell

and here for the slider cell :

class SliderCell: UITableViewCell {

@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var maxLegendLabel: UILabel!
@IBOutlet weak var minLegendLabel: UILabel!
@IBOutlet weak var slider: UISlider!
@IBOutlet weak var answerLabel: UILabel!

var delegate: QuestionSliderCellDelegate?

override func awakeFromNib() {

override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

@IBAction func slideAction(sender: UISlider) {
let sliderValue = Int(sender.value)
print("slider value")

func display(block: Block){
titleLabel.text = block.title
slider.value = 1.0


Answer Source

You should try to disable the content delay touches on your UITableView. This will make the slider more responsive and disable every delays on touch.

To do so try this code below:

 override func viewDidLoad() {
        yourTableView.delaysContentTouches = false

 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        for view in tableView.subviews {
            if view is UIScrollView {
                (view as? UIScrollView)!.delaysContentTouches = false
        return numberOfRows
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download