gpt4 book ai didi

ios - Swift 2 无法将 slider 添加到 UITableView 单元格

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:06:52 27 4
gpt4 key购买 nike

我正在尝试使用 swift 在 UItableview 中创建一个 slider 单元格,它出现了,但它不起作用,我想实时显示它的值但它不起作用,我尝试使用 action 在 slider 本身上,我尝试更改 Editing Changed 方法也不起作用。

这是我的手机代码:

import 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!


override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
slider.userInteractionEnabled = true
slider.continuous = true
// slider.addTarget(self, action: #selector(sliderValueChanged), forControlEvents: UIControlEvents.ValueChanged)

}

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

// Configure the view for the selected state
}

@IBAction func sliderAction(sender: UISlider) {
print("slider ACTION value")
print(sender.value)
}

func sliderValueChanged(sender: UISlider) {
print("slider value")
print(sender.value)
answerLabel.text = "Your choice : " + String(sender.value)

}

func displayBlock(block: Block){
titleLabel.text = block.title
minLegendLabel.text = block.range?.legendMin
maxLegendLabel.text = block.range?.legendMax
slider.minimumValue = Float((block.range?.min)!)!
slider.maximumValue = Float((block.range?.max)!)!
slider.value = 1
}
}

这是我在 my tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 方法中声明它的方式:

let cell = tableView.dequeueReusableCellWithIdentifier(CurrentFormTableView.CellIdentifiers.SliderCell, forIndexPath: indexPath) as! SliderCell
cell.displayQuestion(block)
cell.selectionStyle = UITableViewCellSelectionStyle.None
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 160.0
return cell

最佳答案

在 TableView 单元格中添加:

sliderDemo = UISlider(frame:CGRectMake(0, 0, 200,20))
var numberOfSteps : NSInteger = numbers.count - 1
sliderDemo.minimumValue = 6.5
sliderDemo.maximumValue = 4.1
sliderDemo.continuous = true
sliderDemo.value = 4.0
sliderDemo.addTarget(self, action: "sliderValueDidChange:", forControlEvents: .ValueChanged)
self.view.addSubview(sliderDemo)

func sliderValueDidChange(sender:UISlider!)
{
println("number:\(sender.value)")
}

关于ios - Swift 2 无法将 slider 添加到 UITableView 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36939954/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com