簡單的TableView設(shè)置,其他的就去設(shè)置相應(yīng)的一些格式,但最最基本的使用如下。
1,從控件拖出TableView和cells,調(diào)整放好
2,設(shè)置代理UITableViewDataSource,UITableViewDelegate,這里最開始會報錯,那是因為你要去實現(xiàn)delegate的函數(shù)才可以,所以繼續(xù)吧!
3,聲明一個數(shù)組存cells的數(shù)據(jù),一個標(biāo)識符
private var lists = [String]()
let workplaceTableIdentifier = "workplaceTableIdentifier"
4,實現(xiàn)兩個基本方法
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return lists.count
}這個是返回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)識符返回一個可用的table View cell
Got it?這是我的個人理解,歡迎大家指正。