本系列文章 《Swift on iOS 学习笔记》 将以不定长度、不定内容、不定形式的方式对外发布,主要记录一些 “可重用” 的知识,感谢你的阅读。

在继承自 UIViewController 的普通页面中使用 UITableView 是一种非常普遍的需求,因为 UITableViewController 的可定制性是很差的。话不多说,马上开始:

1. 新建 Application

2. 添加一个 Table View

3. 在 Table View 上添加一个 Table View Cell

4. 在左侧选中该 Table View Cell,并赋予它 Identifier

左侧,点击选中:

右侧,在 Identifier 框里面输入小写的 cell ,输入完成后记得按 Enter 确认:

5. 将该 Table View 绑定到代码

取名为 firstTableView。

6. 修改代码

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var firstTableView: UITableView!

    override func viewDidLoad() {
super.viewDidLoad() firstTableView.delegate = self
firstTableView.dataSource = self
} override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell cell.textLabel.text = "我是第 \(indexPath.row) 个Cell" return cell
} }

7. 运行:

8. 总结

此 firstTableView 只是页面上一个普通的 view,可以直接调整他大小和位置,也可以随意增加其他 view。

 
 
 
 

最新文章

  1. IT基础架构规划方案一(网络系统规划)
  2. Android 学习第16课,java 包、类等相关的一些基础知识
  3. 作业二:Github注册账户过程
  4. JAVA NIO中的Channels和Buffers
  5. SQL SERVER树型数据处理时,函数递归调用问题,查询根节点,子节点函数
  6. spring与mysql整合数据源的配置
  7. 关于Latent Dirichlet Allocation
  8. 编码的UI测试项目——Visual Studio 2013
  9. IOS_视图实现圆角效果的三种方法及比较
  10. eclipse 中使用等宽字体 inconsolata
  11. 小猪Android越来越方式 Day 5 - part 2
  12. 计算机程序的思维逻辑 (70) - 原子变量和CAS
  13. c++调用python系列(1): 结构体作为入参及返回结构体
  14. Web测试与APP测试有哪些异同?
  15. overflow-x: scroll;横向滑动详细讲解
  16. golang项目git-subtree完美解决差异包管理
  17. [Redis] redis的设计与实现-对象系统
  18. There Are Now 3 Apache Spark APIs. Here’s How to Choose the Right One
  19. oracle授权表权限给用户
  20. RabbitMQ在特来电的深度应用

热门文章

  1. C++ Lambda表达式和仿函数笔记
  2. MongoDB 学习三
  3. Android Studio 模拟器无法打开 emulator: ERROR: x86 emulation currently requires hardware
  4. leetcode 792. Number of Matching Subsequences
  5. 编写按键驱动以及在framework层上报按键事件
  6. CSU - 1529 Equator —— DP 最大连续和子序列
  7. SCAU 还有两个东西 —— 异或
  8. Chrome 插件 Vimium——让你脱离鼠标
  9. BestCoder3 1002 BestCoder Sequence(hdu 4908) 解题报告
  10. js获取dom对象style样式的值