I have added UIStepper in Custom UItableviewcell Programatically.
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!
}
Add action for stepper
func stepperChanged(stepper:UIStepper) {
let row:Int = (stepper.superview?.tag)!
let value:Int = Int(stepper.value)
print("Row : \(row) Value: \(value)")
}
When i pressed a stepper in cell which indexpath.row = 0. it give me same output such as
Row : 0 Value: 1 Row : 0 Value: 1 Row : 0 Value: 1 Row : 0 Value: 1 Row : 0 Value: 1
What is the mistake in my code? i am not able to figure it out this code which is giving me above result.
Please anyone can help me to solve the problem.
Thanks in advance.