override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let Identifier = "item_default"
let cell = tableView.dequeueReusableCell(withIdentifier: Identifier, for: indexPath)
cell.imageView?.image = UIImage(named: "fenlei")
// 添加开关按钮
var switf = UISwitch(frame: .zero)
switf.setOn(false, animated: true)
switf.tag = indexPath.row
switf.addTarget(self, action: #selector(self.switfChange(_:)), for: .valueChanged)
cell.accessoryView = switf
return cell
}
@objc func switfChange(_ sender:UISwitch!){
print("Select SwiftChange isOn = \(sender.isOn) index = \(sender.tag)")
}
网友评论