带滑块的UITableView单元格:触摸无法正常工作swift 2

带滑块的UITableView单元格:触摸无法正常工作swift 2,uitableview,swift2,Uitableview,Swift2,我使用UITableView显示多个自定义单元格,我有一个带有UiSlider的单元格,问题是要移动滑块,我需要长按触摸才能移动它,否则它不会移动。我尝试在UITableView中使用multiples滑块来完成一个简单的项目,效果非常好。所以我想我需要在触摸屏周围配置一些东西,但我不知道是什么。这是我的密码: 在我的视图中,我为手势加载了以下代码: override func viewDidLoad() { super.viewDidLoad() let ta

我使用UITableView显示多个自定义单元格,我有一个带有UiSlider的单元格,问题是要移动滑块,我需要长按触摸才能移动它,否则它不会移动。我尝试在UITableView中使用multiples滑块来完成一个简单的项目,效果非常好。所以我想我需要在触摸屏周围配置一些东西,但我不知道是什么。这是我的密码:

在我的视图中,我为手势加载了以下代码:

 override func viewDidLoad() {
        super.viewDidLoad()
        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(FormViewController.dismissKeyboard))
        view.addGestureRecognizer(tap)

        // without this line bellow you can't select any cell to display multiple or single choice questions
        tap.cancelsTouchesInView = false
        if  self.navigationController!.respondsToSelector(Selector("interactivePopGestureRecognizer")) {
            self.navigationController!.view.removeGestureRecognizer(navigationController!.interactivePopGestureRecognizer!)
        }

        notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), name: UIKeyboardWillHideNotification, object: nil)
        notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), name: UIKeyboardWillChangeFrameNotification, object: nil)

    }
func dismissKeyboard() {
        view.endEditing(true)
    }
对于UITableView
cellForRowAtIndexPath
方法:

        let cell = tableView.dequeueReusableCellWithIdentifier(CurrentFormTableView.CellIdentifiers.SliderCell, forIndexPath: indexPath) as! SliderCell
        cell.delegate = self
        cell.slider.tag = indexPath.row
        cell.display(block)
        cell.selectionStyle = UITableViewCellSelectionStyle.None
        return cell
下面是我的滑动单元格的代码:

导入UIKit

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() {
        super.awakeFromNib()
    }

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

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


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

    }
}

当您在UITableView中使用其他组件(如滑块)并希望获得更好的响应时,可以尝试禁用UITableView上的每个延迟

下面的代码对我很有用:

 override func viewDidLoad() {
        super.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
                break
            }
        }
        return numberOfRows
 }

特别是,
yourTableView.delaysContentTouches=false
对我的案例有效。如果它没有得到修复,则此链接中还有另一个解决方案