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

编程入门 行业动态 更新时间:2024-10-03 08:17:01
本文介绍了带有滑块的UITableView单元格:触摸无法正常工作swift 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用UITableView显示多个自定义单元格,而我有一个带有UiSlider的单元格,问题是要移动滑块,我需要长按才能移动它,否则它就不会移动.我试图用UITableView中的倍数滑块来做一个简单的项目,它可以完美地工作.所以我想我需要围绕触摸配置一些东西,但是我不知道是什么.这是我的代码:

I m using a UITableView to display multiple custom cells, and I have one with a UiSlider, the problem is that to move the slider I need to do a long press touch to be able to move it otherwise it don't move. I tried to do a simple project with multiples slider in a UITableView and it works perfectly. So I suppose I need to configure some thing around the touch but I don't know what. Here is my code :

我的视图中有此代码确实已加载手势:

I have this code in my view did load for gesture :

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方法:

For the UITableView cellForRowAtIndexPath method :

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

这是我的滑块单元格的代码:

And here is the code for my slider 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上的每个延迟.

When you use other components like sliders in UITableView and you want to get better responsiveness, you could try to disable every delay on your UITableview.

以下代码对我来说很有效:

The code below work well for me:

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 }

更多推荐

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

本文发布于:2023-11-26 09:54:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633633.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   单元格   滑块   工作   swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!