Swift练习小demo tableView 自定义cell 简单实用
来源:互联网 发布:枪林弹雨刷枪软件 编辑:程序博客网 时间:2024/06/04 18:13
import UIKitclass ViewController: UIViewController , UITableViewDataSource, UITableViewDelegate { var tableView : UITableView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. tableView = UITableView(frame: CGRect(x: 0, y: 30, width: self.view.bounds.size.width, height: self.view.bounds.size.height), style: UITableViewStyle.plain) tableView.delegate = self tableView.dataSource = self self.view .addSubview(tableView) tableView .register(GoodsTableViewCell.classForCoder(), forCellReuseIdentifier: "cell") } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 20 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell1:GoodsTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! GoodsTableViewCell cell1.titleLable.text = String(indexPath.row) return cell1 } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { print("\(indexPath.row)") } }
import UIKitclass GoodsTableViewCell: UITableViewCell {// var titleLable : UILabel? override init(style: UITableViewCellStyle, reuseIdentifier: String?){ super . init(style: style, reuseIdentifier: reuseIdentifier) self.contentView .addSubview(self.titleLable) } //懒加载label lazy var titleLable:UILabel = { let titleLable = UILabel(frame:CGRect.init(x: 100, y: 0, width: 100, height: 30)) print("----------888") titleLable.backgroundColor = .green titleLable.textAlignment = NSTextAlignment.center return titleLable }( ) required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state }}
0 0
- Swift练习小demo tableView 自定义cell 简单实用
- swift 练习小demo 自定义UITabBarController navBar VC 简单框架
- IOS swift 自定义Tableview cell
- Swift TableView自定义Cell的高度
- iOS swift 自定义tableView不显示cell
- Swift 简单联系小Demo
- swift:ViewController中自定义tableView简单入门
- swift 自定义cell -----------------------简单学习--------第一篇
- tableView自定义cell
- 自定义tableview cell
- iOS tableview自定义cell
- swift tableview cell自适应高度
- 用 swift 纯代码自定义 TableViewCell ,以及自定义 cell 在 TableView 中的调用
- ios 自定义cell demo
- UIKit-TableView--TableView用代码自定义cell
- Swift中自定义Cell
- TableView中实现自定义cell
- 自定义TableView 继承, cell, model
- HMM之Viterbi算法
- 提交代码到svn后,重新将原类(未做任何修改)和svn做对比时,发现svn上的代码仍然是提交之前的,而历史记录中显示的类却是提交之后的
- 电子商务网站功能模块汇总
- 非正式协议和正式协议的区别
- yum 问题集锦
- Swift练习小demo tableView 自定义cell 简单实用
- 手机号码滚动抽奖系统(JS)
- 姚虹波:移动电商之路怎么走
- JS模块化工具requirejs教程(一)
- Ambari学习10_ambari安装过程Registration with the server failed和[Errno 256] No more mirrors to try
- 【cocos2d-js官方文档】十七、事件分发机制
- 42.淘宝商城中的缓存(hasmap)
- solr在java中的使用
- 堆排序java实现