Swift基础之侧滑Cell显示操作按钮

好久没写过博客了,今天展示一个UITableView基础的内容侧滑Cell的方法使用,之前写过OC语言的http://blog.csdn.net/hbblzjy/article/details/51781766,也可以看一看

这个Demo有用到结构体添加数据内容,还有警告框,代码比较简单,不做讲解,自行研究

var myTableView = UITableView()
    var dataArray = [namePhone(name:"张三",phone:"1111111111"),namePhone(name:"李四",phone:"2222222222"),namePhone(name:"小名",phone:"3333333333"),namePhone(name:"小红",phone:"44444444444"),namePhone(name:"小刚",phone:"5555555555"),namePhone(name:"小李",phone:"6666666666"),namePhone(name:"消耗",phone:"7777777777")]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        myTableView = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height), style: .plain)
        myTableView.delegate = self
        myTableView.dataSource = self
        myTableView.rowHeight = 100
        self.view.addSubview(myTableView)
    }
    //MARK:----------UITableViewDelegate,UITableViewDataSource
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArray.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var myCell = tableView.dequeueReusableCell(withIdentifier: "cell")
        if myCell == nil {
            myCell = UITableViewCell.init(style: .value1, reuseIdentifier: "cell")
        }
        myCell?.selectionStyle = .none
        
        let namePho = dataArray[indexPath.row]
        myCell?.textLabel?.text = namePho.name
        myCell?.detailTextLabel?.text = namePho.phone
        
        return myCell!
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        //添加一个警告框
        let alertContro = UIAlertController.init(title: "温馨提示", message: "展示的是侧滑进行操作的Demo", preferredStyle: .alert)
        let okAction = UIAlertAction.init(title: "确定", style: .default) { (action) in
            print("此时点击的是。。。确定。。。按钮")
        }
        let cancleActi = UIAlertAction.init(title: "取消", style: .cancel) {
            (action) in
            print("此时点击的是。。。取消。。。按钮")
        }
        alertContro.addAction(okAction)
        alertContro.addAction(cancleActi)
        self.present(alertContro, animated: true, completion: nil)
    }
    //设计侧滑按钮
    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        
        let deleteRowAc = UITableViewRowAction.init(style: .default, title: "

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hbblzjy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值