Swift3.0创建UItableview

直接上代码:
self.tableView = UITableView(frame: CGRect(x:0.0, y:0.0,width: 320,height: 520), style: UITableViewStyle.plain)
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.tableFooterView = UIView()
self.tableView.rowHeight = 80
view.addSubview(self.tableView)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")

//扩展
extension ViewController : UITableViewDataSource,UITableViewDelegate,tableviewdelgate{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 90
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell",for:indexPath)
if cell.isEqual(nil) {
cell = TableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
}
cell.textLabel?.text="真是麻烦"
cell.backgroundColor=UIColor.red
cell.selectionStyle = .none
// cell.strr="dferfrfr"
// cell.delegate=self
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

}
func thisCellIsGood(name:NSString){
    
}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容