我在TableView的View上有40个UISwitch。我给交换机一个#selector objc函数。 objc函数只能将发送方(UISwitch)作为参数。有没有办法描述哪个开关正在调用objc函数?字段UISwitch.description是不可变的。
答案 0 :(得分:0)
在cellForRowAt
内部做
cell.switch.tag = indexPath.row
@objc func switchChanged(_ sender:UISwitch) {
print(arr[sender.tag]) // model item of the changed switch
}