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的更多相关文章

  1. Swift - 使用storyboard创建表格视图(TableViewController)

    项目创建完毕后,默认是使用ViewController作为主界面视图.下面通过样例演示,如何使用TableViewController作为主界面视图,同时演示如何在storyboard中设置表格及内部 ...

  2. Swift基础--使用TableViewController自定义列表

    首先建立一个swift项目,把storyboard的内容删掉,添加一个 Navigation Controller,然后设置storyboard对应界面的class,在Navigation Contr ...

  3. Swift基础--使用TableViewController自己定义列表

    首先建立一个swift项目,把storyboard的内容删掉,加入一个Navigation Controller.然后设置storyboard相应界面的class,在Navigation Contro ...

  4. 【Swift】Alamofile网络请求数据更新TableView的坑

    写这篇BLOG前,有些话不得不提一下,就仅当发发恼骚吧... 今天下午为了一个Alamofire取得数据而更新TableView的问题,查了一下午的百度(360也是见鬼的一样),竟然没有一个简单明了的 ...

  5. Swift开发iOS应用过程中的问题和解决记录

    虚拟机里安装OSX+XCode开发环境 用真机的请直接跳过这个部分. 主要是在VitrualBox里安装mac系统和xcode,参考这篇教程,VirtualBox的版本是4.3.18 r96156,O ...

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

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

  7. swift 下storyboard的页面跳转和传值

    ------------------1. 最简单的方法 拖拽, 这个就不用多解释了吧. 直接拖拽到另一个视图控制器, 选择 show, 就行了. 2. 利用 Segue 方法 (这里主要是 方法1 的 ...

  8. iOS开发 Swift开发数独游戏(三) 选关界面

    一.选关界面涉及到的功能点 1)需要UITableView以及相应数据代理.协议的实现 2)读取plist文件并转化成模型 3)在单元格点击后进入数独游戏,涉及到把数据经segue在UIViewCon ...

  9. SnapKit swift实现高度自适应的新浪微博布局

    SnapKit swift版的自动布局框架,第一次使用感觉还不错. SnapKit是一个优秀的第三方自适应布局库,它可以让iOS.OS X应用更简单地实现自动布局(Auto Layout).GtiHu ...

随机推荐

  1. Composer fails to download http json files on "update", not a network issue, https fine

    "repositories": [ { "packagist": false }, { "type": "composer&quo ...

  2. 喵神 onevcat 的直播首秀

    喵神 onevcat 的直播首秀   王巍在圈内人称喵神,我和他在网上很早就认识,平时多有交流.在我眼中,他是一个幽默风趣高手.虽然他的博客中主要内容是 iOS 开发,但是他实际上涉及的技术领域还包括 ...

  3. locatin

    //location对象 //初始url:http://www.wrox.com/WileyCDA: //将URL修改为:http://www.wrox.com/WileyCDA/#section1 ...

  4. FragmentTabHost的应用

    原创)FragmentTabHost的应用(fragment学习系列文章之二) 时间 2014-04-14 00:11:46  CSDN博客 原文  http://blog.csdn.net/flyi ...

  5. netifd

    Netifd是OpenWrt中用于进行网络配置的守护进程,基本上所有网络接口设置以及内核的netlink事件都可以由netifd来处理完成. 在启动netifd之前用户需要将所需的配置写入uci配置文 ...

  6. 示例 - 如何在多线程中应用SpiderStudio生成的DLL?

    >> 接上文 "示例 - 如何在Console应用程序中应用SpiderStudio生成的DLL?", 将其改成多线程: 代码: using System; using ...

  7. 百度JS模板引擎

    1. 应用场景 前端使用的模板系统  或  后端Javascript环境发布页面 2. 功能描述 提供一套模板语法,用户可以写一个模板区块,每次根据传入的数据,生成对应数据产生的HTML片段,渲染不同 ...

  8. js学习笔记23----窗口尺寸及窗口事件

    窗口尺寸: 可视区的尺寸 document.documentElement.clientWidth document.documentElement.clientHeight 滚动距离 documen ...

  9. Unity UGUI实现Button按钮长按状态的判断

    代码: using UnityEngine.EventSystems; using System.Collections; /// <summary> /// 脚本位置:UGUI按钮组件身 ...

  10. 【BZOJ】1645: [Usaco2007 Open]City Horizon 城市地平线(线段树+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1645 这题的方法很奇妙啊...一开始我打了一个“离散”后的线段树.............果然爆了. ...