Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Uitableviewcell中的UIStepper值未更改_Ios_Swift_Uistepper - Fatal编程技术网

Ios Uitableviewcell中的UIStepper值未更改

Ios Uitableviewcell中的UIStepper值未更改,ios,swift,uistepper,Ios,Swift,Uistepper,我以编程方式在自定义UItableviewcell中添加了UIStepper func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("subServiceCell", forIndexPath: indexPath)

我以编程方式在自定义UItableviewcell中添加了UIStepper

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("subServiceCell", forIndexPath: indexPath) as? RE_RepairSubServiceCell
    let stepperUnit:UIStepper = UIStepper()
    stepperUnit.frame = CGRectMake(200,75, 94, 29);
    stepperUnit.tag = indexPath.row + 1000
    stepperUnit.value = 0.0
    stepperUnit.wraps = true
    stepperUnit.autorepeat = false
    stepperUnit.stepValue = 1.0
    stepperUnit.minimumValue = 0.0
    stepperUnit.maximumValue = 100.0
    stepperUnit.continuous = true
    stepperUnit.addTarget(self, action:#selector(RE_RepairSubServiceVC.stepperChanged(_:)), forControlEvents: .ValueChanged)
    cell!.addSubview(stepperUnit)
    return cell!
}
为步进器添加操作

func stepperChanged(stepper:UIStepper) {
    let row:Int = (stepper.superview?.tag)!
    let value:Int = Int(stepper.value)
    print("Row : \(row) Value: \(value)")

} 
当我在indexpath.row=0的单元格中按下一个步进器时。它给我相同的输出,比如

Row : 0 Value: 1 Row : 0 Value: 1 Row : 0 Value: 1 Row : 0 Value: 1 Row : 0 Value: 1 行:0值:1 行:0值:1 行:0值:1 行:0值:1 行:0值:1 我的代码中有什么错误?我无法理解这段代码给出的结果

请任何人都能帮我解决这个问题


提前感谢。

当我使用默认单元格检查代码时,您的代码工作正常,自定义单元格创建可能存在一些问题,如果您的单元格超出可见区域,您的步进器值将重置谢谢您宝贵的时间@Pyro。我已经解决了这个问题。问题是当我按下步进器时,单元格被重新创建。这就是为什么步进器的值被重置的原因。