2,StoryBoard设置
(1)将单元格 cell 的 identifier 设置成“myCell”
例子
import UIKit
class ViewController: UIViewController , UITableViewDelegate, UITableViewDataSource {
var catalog = [[String]]()
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
//初始化列表数据
catalog.append(["第一节:Swift 环境搭建",
"由于Swift开发环境需要在OS X系统中运行,下面就一起来学习一下swift开发环境的搭建方法。"])
catalog.append(["第二节:Swift 基本语法。这个标题很长很长很长。",
"本节介绍Swift中一些常用的关键字。以及引入、注释等相关操作。"])
catalog.append(["第三节: Swift 数据类型",
"Swift 提供了非常丰富的数据类型,比如:Int、UInt、浮点数、布尔值、字符串、字符等等。"])
catalog.append(["第四节: Swift 变量",
"Swift 每个变量都指定了特定的类型,该类型决定了变量占用内存的大小。"])
catalog.append(["第五节: Swift 可选(Optionals)类型",
"Swift 的可选(Optional)类型,用于处理值缺失的情况。"])
//创建表视图
self.tableView.delegate = self
self.tableView.dataSource = self
//设置estimatedRowHeight属性默认值
self.tableView.estimatedRow.0;
//rowHeight属性设置为UITableViewAutomaticDimension
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
//在本例中,只有一个分区
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1;
}
//返回表格行数(也就是返回控件数)
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.catalog.count
}
//创建各单元显示内容(创建参数indexPath指定的单元)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("myCell",
forIndexPath: indexPath) as UITableViewCell
//获取对应的条目内容
let entry = catalog[indexPath.row]
let titleLabel = cell.viewWithTag(1) as! UILabel
let subtitleLabel = cell.viewWithTag(2) as! UILabel
titleLabel.text = entry[0]
subtitleLabel.text = entry[1]
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级