美文网首页
Swift3.0创建UItableview

Swift3.0创建UItableview

作者: 涛涛灬灬 | 来源:发表于2017-03-21 09:52 被阅读0次

直接上代码:
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){
    
}

}

相关文章

网友评论

      本文标题:Swift3.0创建UItableview

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