iOS-UITabVIew Cell 添加 switf
2019-12-21 本文已影响0人
久百一
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)")
}