美文网首页
Swift   TableView 简单使用

Swift   TableView 简单使用

作者: 张小博ios | 来源:发表于2017-08-03 17:21 被阅读0次

class ViewController:UIViewController,UITableViewDataSource{

override funcviewDidLoad() {

super.view DidLoad()

set Up UI()

}

创建多少行

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

return20

}

实现数据展示

functableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{

letcell = tableView.dequeueReusableCell(withIdentifier:"CellID", for: indexPath)

cell.textLabel?.text ="Mr.zhang\(indexPath.row)"

returncell

}

创建tableView

func setUpUI() {

//1.创建表格

let tv = UITableView.init(frame: view.bounds , style: .plain)

view.addSubview(tv)

//注册

tv.register(UITableViewCell.self, forCellReuseIdentifier:"CellID")

//设置数据源

tv.dataSource =self

}

}

Swift   TableView 简单使用

相关文章

网友评论

      本文标题:Swift   TableView 简单使用

      本文链接:https://www.haomeiwen.com/subject/hfgplxtx.html