美文网首页
iOS-UITabVIew Cell 添加 switf

iOS-UITabVIew Cell 添加 switf

作者: 久百一 | 来源:发表于2019-12-21 20:02 被阅读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)")
    }

相关文章

网友评论

      本文标题:iOS-UITabVIew Cell 添加 switf

      本文链接:https://www.haomeiwen.com/subject/ulzgnctx.html