2
私はUITableViewを使用して複数のカスタムセルを表示していますが、UiSliderを使用していますが、問題はスライダを動かすことです。それを動かすことができなければそれは動かない。私はUITableViewで複数のスライダを持つ単純なプロジェクトをやろうとしましたが、完全に動作します。だから私はタッチの周りにいくつかのものを設定する必要があると思うが、私は何がわからない。ジェスチャーのための負荷をしたスライダ付きのUITableViewセル:タッチが正しく動作しないswift 2
私は私の見解では、このコードを持っている:ここに私のコードがあるのUITableView cellForRowAtIndexPath
方法については
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)
}
:
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
}
}