簡單的TableView設(shè)置寓搬,其他的就去設(shè)置相應(yīng)的一些格式,但最最基本的使用如下双揪。
1动羽,從控件拖出TableView和cells,調(diào)整放好
2渔期,設(shè)置代理UITableViewDataSource,UITableViewDelegate运吓,這里最開始會(huì)報(bào)錯(cuò),那是因?yàn)槟阋?shí)現(xiàn)delegate的函數(shù)才可以疯趟,所以繼續(xù)吧拘哨!
3,聲明一個(gè)數(shù)組存cells的數(shù)據(jù)信峻,一個(gè)標(biāo)識(shí)符
private var lists = [String]()
let workplaceTableIdentifier = "workplaceTableIdentifier"
4倦青,實(shí)現(xiàn)兩個(gè)基本方法
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return lists.count
}這個(gè)是返回cells的數(shù)量,根據(jù)lists的數(shù)量來
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(workplaceTableIdentifier, forIndexPath: indexPath)
cell.textLabel?.text = lists[indexPath.row]
cell.textLabel?.font = UIFont .systemFontOfSize(14)
return cell
}根據(jù)標(biāo)識(shí)符返回一個(gè)可用的table View cell
Got it盹舞?這是我的個(gè)人理解产镐,歡迎大家指正。