我正在使用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
发布评论