// 实现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

Swift - 实现tableView单选系统样式相关推荐

  1. tableView的plain样式的headerView的上拉过程中悬停解决方法

    tableView的plain样式的headerView的上拉过程中悬停解决方法 参考文章: (1)tableView的plain样式的headerView的上拉过程中悬停解决方法 (2)https: ...

  2. Drupal 覆写系统样式

    如果要覆写系统样式,需要在指定的theme中的theme.info中做指定,假设需要覆写 modules/system/system-menus.css 样式文件,就需要在theme.info中增加或 ...

  3. MUI 如何更改单选框样式

    自定义修改 MUI 单选框的默认样式 效果图,对比示下: 以上图效果为例: 修改前代码:[参考mui.min.css ] 修改后代码如下:.mui-radio input[type=radio]:ch ...

  4. html改变单选形状,用css实现html中单选框样式改变

    我们都知道,input的单选框是一个小圆框,不能直接更改样式.但是我们在很多网页中看到的单选框样式可不仅限于默认的那个样式(看上去没啥新意,也比较丑).那么,接下来我将介绍下如何实现该功能. 首先,让 ...

  5. android获得系统自带颜色,这些Android系统样式中的颜色属性你知道吗?

    Android 系统样式中的颜色属性 几个常用的颜色属性 先放上一张经典的图片,图片来自网络. 这张图在网上很是流传,也不知道当初是哪位大神标注的,很好的说明了 Android 系统中的几个常用的颜色 ...

  6. vue 单选框样式_作为一位Vue工程师,这些开发技巧你都会吗?

    来源 | http://www.cnblogs.com/chanwahfung/p/12543103.html 路由参数解耦 一般在组件内使用路由参数,大多数人会这样做: export default ...

  7. 修改element单选框样式

    .el-radio__input.is-checked .el-radio__inner {//单选框选择按钮背景样式border-color: #409EFF;background: #FFF; } ...

  8. Android系统自带主题样式(android:theme),Android Dialog 系统样式

    部分转载:http://stephen830.iteye.com/blog/1129203 ,  http://blog.sina.com.cn/s/blog_3e333c4a0102vk0f.htm ...

  9. Windows核心编程_让窗口跟随系统样式变化

    当我们使用 VS 编写win32程序时,窗口会有点丑,这个是因为GDI库,Windows有自己的UI库代码,但是版本很多,不同内核版本使用的GUI库不一样,一般vs在编译win32程序时会给你加载一个 ...

  10. iOS开发,tableView在Grouped样式下,表头表尾空白问题解决

    1.estimatedRowHeight.estimatedSectionHeaderHeight.estimatedSectionFooterHeight均设为0 2.表头高度sectionHead ...

最新文章

  1. 开发板tftp:timeout问题
  2. Unable to load the Wrapper's native library because none of the following files及解决方法
  3. 设计HTML标签title属性值换行
  4. 【标注图像】windows下使用labelImg
  5. 开通5G网络服务三个月,中国广电交出了什么样的答卷?
  6. 3ds Max 2014破解版安装中遇到的问题及解决
  7. 工业相机 - - 线阵相机
  8. 迪赛智慧数——柱状图(折柱混合图):应届生薪酬变化趋势
  9. 如何看待社会的阴暗面
  10. ReversingWithLena——01. Olly + assembler + patching a basic reverseme
  11. wireshark 过滤omci包_中兴OLT、ONU常见故障问题处理
  12. 等级保护基本要求四级通用要求
  13. PSP用DOS模拟器DOSBOX 0.71版发布
  14. DDOS攻击和CC攻击分别是什么?
  15. 研讨会 | 知识图谱助力图书馆知识管理与智慧服务研讨会
  16. C# 异常处理 浮兮vip解析
  17. Python平均工资1万5,不懂英文能学吗?
  18. C Primer Plus第五版记录
  19. 【R329开发板评测】R329开发板部署aipu模型
  20. 重置计算机win7,win7重置系统,开机一键还原win7系统

热门文章

  1. java分布式商城项目环境搭建1-CentOS7.6-安装JDK1.8
  2. 深入探索Java泛型
  3. HttpClient Util 工具
  4. MySQLdb查询有中文关键字查不到数据
  5. Flyweight模式
  6. mysql 常用函数总计
  7. robot framework -重点记录
  8. quick cocos2dx 3.3 踩坑日记(三)------ setPOSTData
  9. hello!!大家好
  10. java, android的aes等加密库