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
}
}
Swift - 实现tableView单选系统样式的更多相关文章
- swift学习 - tableView自适应高度2(SnapKit Layout)
SnapKit是Swift中自动布局的框架,相当于Objective-C中的Masonry 下面是tableView自定义cell,使用SnapKit布局的效果图: 详细代码如下: TYCustomC ...
- 用css实现html中单选框样式改变
我们都知道,input的单选框是一个小圆框,不能直接更改样式.但是我们在很多网页中看到的单选框样式可不仅限于默认的那个样式(看上去没啥新意,也比较丑).那么,接下来我将介绍下如何实现该功能. 首先, ...
- 复选框、单选框样式自定义(https://www.cnblogs.com/freedom-feng/p/11346396.html)
复选框.单选框样式自定义(https://www.cnblogs.com/freedom-feng/p/11346396.html)复选框html内容如下:<input type="c ...
- 这些Android系统样式中的颜色属性你知道吗?
Android 系统样式中的颜色属性 推荐阅读看完后彻底搞清楚Android中的 Attr . Style .Theme 几个常用的颜色属性 先放上一张经典的图片,图片来自网络. 这张图在网上很是流传 ...
- swift UITableViewCell 中的单选控制样式
我昨天在网上找了一晚上的资料,但是大多都是OC得语法,swift资料实在是太少了,使得我这个刚入门swift的彩笔好不吃力,后面一直各种翻阅资料,终于让我找到了 visibleCells 这个方法,直 ...
- ios开发之--tableview单选/多选实现(非tableview的editing状态)及默认选中
实现思路比较简单,这里仅做记录: 直接上代码: 1,实现didSelectRowAtIndexPath方法 -(void)tableView:(UITableView *)tableView didS ...
- swift 定制自己的Button样式
swift的UIButton类中有些公开方法可以重写,所以,如果想写出自己的UIButton,只要继承UIButton类,并重写相应的方法即可. 系统的UIButton可以添加图片,也可以添加标题,但 ...
- swift 创建tableView并实现协议
// // ViewController2.swift // swift_helloword // // Created by Charlie on 15/7/13. // Copyright (c) ...
- Swift - 使用TableView的静态单元格进行页面布局
通过使用静态单元格的列表,我们可以很方便的进行页面布局.下面通过一个“添加任务页面”来进行演示. 效果图如下: 实现步骤: 1,在storyboard中拖入一个TableViewController, ...
随机推荐
- linux下node-webkit安装vlc插件
一.下载node-webkit 下载linux版本的node-webkit,网址如下:https://github.com/rogerwang/node-webkit.文件解压之后又如下几个文件,其中 ...
- node-webkit播放目录下所有网页文件
1.编写index.html文件 这里我们需要播放某一个目录下所有的网页文件,要做到切换不同的网页,可以在index.html中使用iframe.通过js动态改变iframe的src属性,从而动态地切 ...
- fprintf宏
最近在调试程序,使用printf函数和调试信息都不能在终端输出,所以使用比较笨的方法.将调试信息写到文件中,再查看文件.由于要多次使用fprintf函数,所以将其写成宏. 参考链接: http://w ...
- MongoDB C Driver Building on Windows
一.编译mongodb c driver: 需要先安装OpenSSL:(参见:http://bbs.aircheng.com/read-2222-1) 步骤:(MongoDB步) 1.下载Active ...
- Stream(流)的基本操作
//把流转化为文件 public static void StreamToFile(Stream stream, string filepath) { byte[ ...
- java基础——Collections.sort的两种用法
Collections是一个工具类,sort是其中的静态方法,是用来对List类型进行排序的,它有两种参数形式: public static <T extends Comparable<? ...
- Sqlserver2005:深入了解php执行sqlserver存储过程procedure:odbc_exe、odbc_execute
以下存储过程(伪代码): -- 伪代码,假设相关操作是成功的 alter procedure pr_test as begin set nocount on update tab set col='n ...
- Ubuntu创建新用户并增加管理员权限
1.Ubuntu中的root帐号默认是被禁用了的,所以登陆的时候没有这个账号 打开终端开启root账户 sudo passwd -u root sudo passwd root 设置root密码,输入 ...
- php 中的 short_open_tag 的作用
在php的配置文件(php.ini)中有一个short_open_tag的值,开启以后可以使用PHP的段标签:(<? ?>). 同时,只有开启这个才可以使用 <?= 以代替 < ...
- supervisorctl unix:///var/run/supervisor.sock refused connection
运行supervisorct 报如下错误 supervisorctl unix:///var/run/supervisor.sock refused connection 查看supervisord. ...