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, ...
随机推荐
- Cygwin镜像使用帮助
Cygwin镜像使用帮助 收录架构 x86 x86_64 收录版本 所有版本 更新时间 每12小时更新一次 使用说明 选择从互联网安装, 在"User URL"处输入以下地址 ...
- table获取checkbox是否选中的几种方法
function test() { $(".table tbody tr").find("td:first input:checkbox").each(func ...
- 【R】用 ggplot2 绘制漂亮的分级统计地图
最近我一直尝试利用R绘制地图,我从网上找到了上百种不同的实现方法,然而其中却没有适用于我的数据的方法.最终,我从以下几个博客[1]中找到了灵感.我在整合这些资源的基础上,通过不断的试验和修正得到了一个 ...
- 查询相应id下的数据
---恢复内容开始--- u方法这样的:带不起模板引擎 <a href="{:U('Del/wzxg','','')}/{$vo.id}">修改</a> 这 ...
- 【转】C#获取电脑客户端IP地址及当前用户名
在C#中获取一台电脑名,IP地址及当前用户名是非常简单,以下是我常用的几种方法: 1. 在ASP.NET中专用属性: 获取服务器电脑名:Page.Server.ManchineName 获取用户信息: ...
- peek函数的用法
#include <iostream> /* run this program using the console pauser or add your own getch, system ...
- 关于HTTP keep-alive的实验(转至 http://my.oschina.net/flashsword/blog/80037)
前面一篇文章提到,HTTP1.1中持久连接已经是默认配置,除非设置Connection为close,否则默认都会进行持久连接.但是我们知道事实标准跟教科书还是可能会有一定差距的,所以不妨自己尝试一下. ...
- c#后台常用知识
生成如:2015-10-25T12:12:12格式的时间 DateTime.Now.ToString("s") 非asp.net mvc环境下对url编码 (HttpUtility ...
- 基于SSH框架、Oracle数据库、easyui的分页显示
要求:在easyui-datagrid中完成paginaton的分页功能. 1.easyui-datagrig的配置 <table id="dg" rownumbers=tr ...
- c++获取cpu信息
原文地址:http://blog.csdn.net/jamesliulyc/article/details/2028958 1.什么是cpuid指令 CPUID指令是intel IA32架构下获得CP ...