//

//  ViewController.swift

//  UITableView

//

//  Created by lanou on 16/11/7.

//  Copyright (c) 2016年 lanou. All rights reserved.

//

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

//style:(1).Palin 分区之间没有间距 (2).Group分区之间有间距

let tableView = UITableView(frame: view.bounds, style: UITableViewStyle.Plain)

//设置数据源代理(提供视图相关操作)

tableView.delegate = self

//负责提供数据

tableView.dataSource = self

view.addSubview(tableView)

//给tableView注册cell,当有cell滑出屏幕的时候会将单元格cell放到缓存池中并且给上重用标识符cell

tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

//遵循多个协议采用逗号隔开

extension ViewController:

UITableViewDelegate,UITableViewDataSource{

//返回每个分区的行数

func tableView(tableView:

UITableView, numberOfRowsInSection section: Int) -> Int {

return 500

}

//返回每个单元格,单元格:UITableViewCell,NSIndexPath是存储该单元格是第几分区,第几行

func tableView(tableView:

UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

//每一个单元格对应着一个UItableViewCell.其中封装了三个属性:imageView,textLable,detailTextLabel

// let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell")

//tableView根据重用标识符"cell"到缓存池中查找有没有缓存的cell,有的话取出来使用,没有的话创建

let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell!

//标题视图textLable

cell.textLabel?.text = "老司机"

//副标题视图detailTextLabel

cell.detailTextLabel?.text = "带带我"

//图片视图

cell.imageView?.image = UIImage(named: "bg_3.png")

return cell

}

}

最新文章

  1. android源码中,在系统多媒体数据库中增加一个字段
  2. Beagleboard xm sd卡恢复
  3. js事件监听器用法实例详解
  4. fibonacci数列(二)_矩阵快速幂
  5. UVa 1339 Ancient Cipher --- 水题
  6. ANativeWindow是个什么东西
  7. ADO.NET笔记——带参数的查询防止SQL注入攻击
  8. Apache 编译安装
  9. Container容器控件的使用、Hbox与Vbox布局管理器的使用、以及AjaxAction前后台事件响应
  10. CSS 尺寸 (Dimension)
  11. NDEF-NFC数据交换格式
  12. js正则验证手机号码有效性
  13. [bzoj1999]树网的核
  14. String类详解
  15. Web服务中延时对QoE(体验质量)的影响
  16. dblink 退出 session
  17. 20145313张雪纯exp7
  18. 什么是JavaBean、bean? 什么是POJO、PO、DTO、VO、BO ? 什么是EJB、EntityBean?
  19. SSM总结
  20. Object中有哪些方法?

热门文章

  1. 2017年江西理工大学C语言程序设计竞赛(初级组)
  2. mybatis深入理解(一)之 # 与 $ 区别以及 sql 预编译
  3. 练习十八:求这样的一组数据和,s=a+aa+aaa+aaaa+aa...a,其中a为一个数字
  4. 转 GTID复制的搭建和问题处理
  5. Murano PTL&Core
  6. Hive 环境的安装部署
  7. Http报文长度的计算
  8. Shell笔试题2
  9. 安装flask-mysqldb的时候,提示 mysql_config not found 的解决方法
  10. hibernate课程 初探单表映射3-5 hibernate增删改查