swift tableViewController
tableViewController 控制器
import UIKit
class ViewController: UITableViewController {
// 静态数据数组,存放模型
var arrs = [ZLPlace]()
override func viewDidLoad() {
super.viewDidLoad()
let place2 = ZLPlace()
place2.place = "zhang2"
arrs.append(place2)
let place3 = ZLPlace()
place3.place = "zhang3"
arrs.append(place3)
let place4 = ZLPlace()
place4.place = "zhang1"
arrs.append(place4)
self.tableView.reloadData()
}
// 数据源方法, 返回多少组
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1;
}
// 每组有多少行
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrs.count;
}
// 每行展示什么内容
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
let place = arrs[indexPath.row]
cell.textLabel.text = place.place
return cell;
}
// 点击每个cell触发什么事件
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let place = arrs[indexPath.row]
place.visited = !place.visited;
let cell = tableView.cellForRowAtIndexPath(indexPath)
cell?.backgroundColor = UIColor.clearColor()
if(place.visited){
cell?.accessoryType = UITableViewCellAccessoryType.Checkmark
}else{
cell?.accessoryType = UITableViewCellAccessoryType.None
}
}
// 点击编辑按钮
@IBAction func editing(sender: AnyObject) {
self.tableView.setEditing(true, animated: true)
}
// 删除每个cell
override func tableView(tableView: UITableView, commitEditingStyle
editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath:
NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete{
arrs.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
}
}
}
swift tableViewController的更多相关文章
- Swift - 使用storyboard创建表格视图(TableViewController)
项目创建完毕后,默认是使用ViewController作为主界面视图.下面通过样例演示,如何使用TableViewController作为主界面视图,同时演示如何在storyboard中设置表格及内部 ...
- Swift基础--使用TableViewController自定义列表
首先建立一个swift项目,把storyboard的内容删掉,添加一个 Navigation Controller,然后设置storyboard对应界面的class,在Navigation Contr ...
- Swift基础--使用TableViewController自己定义列表
首先建立一个swift项目,把storyboard的内容删掉,加入一个Navigation Controller.然后设置storyboard相应界面的class,在Navigation Contro ...
- 【Swift】Alamofile网络请求数据更新TableView的坑
写这篇BLOG前,有些话不得不提一下,就仅当发发恼骚吧... 今天下午为了一个Alamofire取得数据而更新TableView的问题,查了一下午的百度(360也是见鬼的一样),竟然没有一个简单明了的 ...
- Swift开发iOS应用过程中的问题和解决记录
虚拟机里安装OSX+XCode开发环境 用真机的请直接跳过这个部分. 主要是在VitrualBox里安装mac系统和xcode,参考这篇教程,VirtualBox的版本是4.3.18 r96156,O ...
- Swift - 使用TableView的静态单元格进行页面布局
通过使用静态单元格的列表,我们可以很方便的进行页面布局.下面通过一个“添加任务页面”来进行演示. 效果图如下: 实现步骤: 1,在storyboard中拖入一个TableViewController, ...
- swift 下storyboard的页面跳转和传值
------------------1. 最简单的方法 拖拽, 这个就不用多解释了吧. 直接拖拽到另一个视图控制器, 选择 show, 就行了. 2. 利用 Segue 方法 (这里主要是 方法1 的 ...
- iOS开发 Swift开发数独游戏(三) 选关界面
一.选关界面涉及到的功能点 1)需要UITableView以及相应数据代理.协议的实现 2)读取plist文件并转化成模型 3)在单元格点击后进入数独游戏,涉及到把数据经segue在UIViewCon ...
- SnapKit swift实现高度自适应的新浪微博布局
SnapKit swift版的自动布局框架,第一次使用感觉还不错. SnapKit是一个优秀的第三方自适应布局库,它可以让iOS.OS X应用更简单地实现自动布局(Auto Layout).GtiHu ...
随机推荐
- 判断是否是IE浏览器和是否是IE11
判断是否是IE浏览器用下面这个函数, function isIE() { //ie? 是ie返回true,否则返回false if (!!window.ActiveXObject || "A ...
- iOS 开发如何入门
iOS 开发如何入门 新人如何入门 上一篇文章的回复中,很多读者让我推荐入门图书.其实我觉得每个人可能有自己喜欢的学习方式,我习惯的不一定适合你.不过我可以分享一下我当时是如何学习 iOS 开发的. ...
- 【LeetCode】065-验证数字
写在前面 前面研究OS的经历实在是令人心力憔悴..所以换个新鲜的,把自己的刷题感悟整理一番.刷了有些题了,就先拿最近几天hard题打头阵吧.首先说的是(065)Valid Number这个题,其实一眼 ...
- mysql 使用 temp
whereis 软件 检查数据库mysqlcheck -uroot -p --all-databases 修复$ mysql -uroot -p databasename REPAIR TABLE t ...
- oozie客户端常用操作命令
1.提交作业,作业进入PREP状态 oozie job -oozie http://localhost:11000/oozie -config job.properties -submit job: ...
- Cookie js 操作
从事web开发也有些日子了,cookie 是个啥差不多能说明白,可是实际自己一上手操作就是得去搜索(你们懂的),结果被鄙视了...所以就写一篇博文做为自己的学习笔记,嘿嘿,博客的好处在此体现出来了. ...
- golang 环境bash 以及shell
standard_init_linux.go:178: exec user process caused "no such file or directory" 2018年04月2 ...
- Istio微服务架构初试
感谢 http://blog.csdn.net/qq_34463875/article/details/77866072 看了一些文档,有些半懂不懂,所以还是需要helloworld一下.因为isti ...
- mysql实现经纬度计算两个坐标之间的距离sql语句
select *,(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(111.86141967773438-latitude)/360),2)+COS(PI()*33.070 ...
- jconsole监控tomcat
一.专业术语 GC垃圾回收机制:当需要分配的内存空间不再使用的时候,JVM将调用垃圾回收机制来回收内存空间. JMX(Java Management Extensions,即Java管理扩展)是一个为 ...