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

}

}

Swift - 实现tableView单选系统样式的更多相关文章

  1. swift学习 - tableView自适应高度2(SnapKit Layout)

    SnapKit是Swift中自动布局的框架,相当于Objective-C中的Masonry 下面是tableView自定义cell,使用SnapKit布局的效果图: 详细代码如下: TYCustomC ...

  2. 用css实现html中单选框样式改变

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

  3. 复选框、单选框样式自定义(https://www.cnblogs.com/freedom-feng/p/11346396.html)

    复选框.单选框样式自定义(https://www.cnblogs.com/freedom-feng/p/11346396.html)复选框html内容如下:<input type="c ...

  4. 这些Android系统样式中的颜色属性你知道吗?

    Android 系统样式中的颜色属性 推荐阅读看完后彻底搞清楚Android中的 Attr . Style .Theme 几个常用的颜色属性 先放上一张经典的图片,图片来自网络. 这张图在网上很是流传 ...

  5. swift UITableViewCell 中的单选控制样式

    我昨天在网上找了一晚上的资料,但是大多都是OC得语法,swift资料实在是太少了,使得我这个刚入门swift的彩笔好不吃力,后面一直各种翻阅资料,终于让我找到了 visibleCells 这个方法,直 ...

  6. ios开发之--tableview单选/多选实现(非tableview的editing状态)及默认选中

    实现思路比较简单,这里仅做记录: 直接上代码: 1,实现didSelectRowAtIndexPath方法 -(void)tableView:(UITableView *)tableView didS ...

  7. swift 定制自己的Button样式

    swift的UIButton类中有些公开方法可以重写,所以,如果想写出自己的UIButton,只要继承UIButton类,并重写相应的方法即可. 系统的UIButton可以添加图片,也可以添加标题,但 ...

  8. swift 创建tableView并实现协议

    // // ViewController2.swift // swift_helloword // // Created by Charlie on 15/7/13. // Copyright (c) ...

  9. Swift - 使用TableView的静态单元格进行页面布局

    通过使用静态单元格的列表,我们可以很方便的进行页面布局.下面通过一个“添加任务页面”来进行演示. 效果图如下: 实现步骤: 1,在storyboard中拖入一个TableViewController, ...

随机推荐

  1. Oracle的sql语句中关键字冲突用双引号

    select distinc user from instrument where created>"TO_DATE"('2015-02-05 12:00:00', 'yyy ...

  2. 用window调用kjb和ktr

    1.    运行cmd,进入kettle的目录cd C:\soft\kettle\data-integration 2.    运行start pan.bat命令 Pan—转换执行器(命令行方式),一 ...

  3. javascript获取URL参数和参数值

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. 关于Android中Fragment静态和动态加载的方法

    一.静态加载 1.首先创建一个layout布局fragment.xml,里面放要显示和操作的控件 2.创建一个layout布局main1.xml,用来实现页面的跳转(跳转为要实现静态加载的界面) 3. ...

  5. Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering

    Defferrard, Michaël, Xavier Bresson, and Pierre Vandergheynst. "Convolutional neural networks o ...

  6. Xshell和SecureCRT等SSH下使用Tmux及Byobu(解决Byobu被statusline信息面板刷屏问题)

    Vim的vsplit用得爽吧!多命令行模式,同样让你爽得不蛋疼! 下面介绍一下两个终端多控制台软件:Tmux 和 Byobu!本文还是以Xshell为主进行介绍! --------------Tmux ...

  7. Javascript农历与公历相互转换

    /**用法 * Lunar.toSolar(2016, 6, 3); 农历转化公历 * Lunar.toLunar(2016, 7, 6); 公历转化农历 */ var Lunar = { MIN_Y ...

  8. iOS 图文混排 (Swift版)

    // 0> 图片附件 let attachment = NSTextAttachment() attachment.image = #imageLiteral(resourceName: &qu ...

  9. VS2010配置HTML5智能提示

    步骤: 1.首先去这里下载安装文件: http://visualstudiogallery.msdn.microsoft.com/d771cbc8-d60a-40b0-a1d8-f19fc393127 ...

  10. css图片宽高相等设置

    <div class="image-header"> <img src="demo.jpg"> </div> .image- ...