В моем приложении у меня есть пользовательский UITableViewCell, и у меня есть UIStepper и UILabel в пользовательской ячейке. Я не знаю, как проверить, какой степпер был нажат. Так это способ узнать, из какой ячейки степпер был нажат? Я использую свифт 3.
я пробовал это
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let data = ["111111", "2222222","3333333"]
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return(data.count)
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
cell.lb1.text = data[indexPath.row]
cell.stepper.tag = indexPath.row
cell.stepper.addTarget(self, action: #selector(stepperA(sender:)), for: .valueChanged)
return (cell)
}
func stepperA (sender: UIStepper){
print("stepper \(sender.tag) clicked. Its value \(sender.value)")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}