UITableView的基本使用

简单的TableView设置,其他的就去设置相应的一些格式,但最最基本的使用如下。

1,从控件拖出TableView和cells,调整放好

2,设置代理UITableViewDataSource,UITableViewDelegate,这里最开始会报错,那是因为你要去实现delegate的函数才可以,所以继续吧!


3,声明一个数组存cells的数据,一个标识符

private var lists = [String]()

let workplaceTableIdentifier = "workplaceTableIdentifier"

4,实现两个基本方法

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return lists.count

}这个是返回cells的数量,根据lists的数量来

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

}根据标识符返回一个可用的table View cell

Got it?这是我的个人理解,欢迎大家指正。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容