我可以在UISwitch中设置描述值吗?

时间:2019-06-21 15:26:09

标签: ios uitableview uiswitch

我在TableView的View上有40个UISwitch。我给交换机一个#selector objc函数。 objc函数只能将发送方(UISwitch)作为参数。有没有办法描述哪个开关正在调用objc函数?字段UISwitch.description是不可变的。

1 个答案:

答案 0 :(得分:0)

cellForRowAt内部做

cell.switch.tag = indexPath.row

@objc func switchChanged(_ sender:UISwitch) { 
   print(arr[sender.tag]) // model item of the changed switch
}