Swift - 实现tableView单选系统样式

// 实现tableView单选

 

import UIKit

 

class ViewController: UIViewController {

    

    var tableView: UITableView!

 

    override func viewDidLoad() {

        super.viewDidLoad()

        

        tableView = UITableView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height), style: .Plain)

        tableView.delegate = self

        tableView.dataSource = self

        self.view.addSubview(tableView)

    }

}

 

extension ViewController: UITableViewDataSource,UITableViewDelegate {

    

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return 20

    }

    

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = UITableViewCell(style: .Default, reuseIdentifier: "cell")

        cell.textLabel?.text = "123"

        return cell

    }

    

    //获取将要选择的单元格的路径

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){

        //取消选中的样式

        tableView.deselectRowAtIndexPath(indexPath, animated: true)

        //获取当前选中的单元格

        let cell:UITableViewCell! = tableView.cellForRowAtIndexPath(indexPath)

        

        //返回所有单元格

        //遍历取消所有单元格样式

        var arry = tableView.visibleCells

        for i in 0 ..< arry.count {

            let cells: UITableViewCell = arry[i]

            cells.accessoryType = .None

        }

        //设置选中的单元格样式

        cell.accessoryType = .Checkmark

    }

}

转载于:https://www.cnblogs.com/gongyuhonglou/p/10311536.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:https://dhexx.cn/news/show-18526.html

如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网进行投诉反馈,一经查实,立即删除!


相关文章:

  • Problems with Ribbon/Feign/Zuul retry
  • 绝大多数人努力程度之低,根本轮不上拼天赋
  • GDTR与LDTR
  • c#之正则表达式
  • Makefile文件(一)_介绍
  • 高级控件 下(三)
  • ArcGIS Python实现Modis NDVI批量化月最大合成
  • crmjs区分窗口是否是高速编辑(2)
  • jQuery Validate验证框架(转载)
  • MD5生成
  • Python_代码练习_写一个判断是否为小数的函数
  • 异常处理-try catch
  • ES6中Number中的扩展
  • 20169302 2016-2017-2 《网络攻防实践》课程总结
  • 九度OJ1451题-信封错装
  • PHP compact
  • Selenium 方法封装 一
  • 访问win10的远程桌面(Remote Desktop)总是凭据或者用户密码错误
  • angular2 --使用DecimalPipe格式化数字
  • 【bzoj1520】[POI2006]Szk-Schools 费用流
  • JQ 按钮实现两种功能
  • 存储控制器和SDRAM 实验
  • Phalcon调试大杀器之phalcon-debugbar安装
  • python sys与shutil模块
  • netty学习指南
  • 关于人生观与方法论的两篇文章
  • Java 8 新特性:3-函数(Function)接口
  • 通过js控制层的动态隐藏
  • iOS自动布局高级用法 纯代码约束写法
  • vue组件(Vue+webpack项目实战系列之三)
  • 6.20
  • 产业企业和投资机会研究 沈阳新松机器人自动化股份有限公司(300024)
  • idea整个项目乱码解决办法
  • 从头认识java-16.4 nio的读与写(ByteBuffer的使用)
  • 宿命的PSS
  • 07_上午内容回顾
  • python三维可视化:配置tvtk
  • working copy is not up-to-date
  • 1.strcpy使用注意
  • html中设置锚点定位的几种常见方法
  • elasticsearch.net search入门使用指南中文版(翻译)
  • 重写( override)and 重载(overload)
  • 【java面试题】equals()方法和==的比较区别?
  • 合并出错:svn Working copy and merge source not ready for reintegration
  • 阿里笔试题:求两个子序列的最大连续子序列
  • 自己手写WEB程序框架并执行
  • Django知识总结
  • Android学习笔记(十二)——使用意图传递数据的几种方式
  • ERP概念介绍
  • LibreOJ β Round #2 E. 数论只会 GCD