tableview懒加载
lazyvartable :UITableView = {
let tables = UITableView(frame: self.view.bounds, style: UITableViewStyle.plain)
returntables
}()
添加到view中,遵守协议,注册cell
self.view!.addSubview(self.table)
self.table.delegate=self
self.table.dataSource=self
self.table.register(UITableViewCell.classForCoder(), forCellReuseIdentifier:"cell")
实现协议方法
funcnumberOfSections(in tableView:UITableView) ->Int{
return10
}
functableView(_tableView:UITableView, numberOfRowsInSection section:Int) ->Int{
return self.name_link_tuples.count
}
functableView(_tableView:UITableView, heightForRowAt indexPath:IndexPath) ->CGFloat{
return100;
}
functableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{
letmodel =self.name_link_tuples[indexPath.row]
letcell = tableView.dequeueReusableCell(withIdentifier:"cell")as!UITableViewCell
cell.textLabel?.text= model.1
returncell
}
备注:
如果有不足或者错误的地方还望各位读者批评指正,可以评论留言,笔者收到后第一时间回复。
QQ/微信:976971956/ljh976971956。
简书号:江湖呼呼:[简书]
感谢各位观众老爷的阅读,如果觉得笔者写的还凑合,可以关注或收藏一下,不定期分享一些好玩的实用的demo给大家。
文/江湖呼呼(简书作者)
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。