python tableview 自适应_swift tableView自适应高度

今天在用swift的时候用到了cell的自适应高度,本来打算运用oc的方法,然而却发现木有用,于是在网上各种翻找,嘿嘿,找到了,原来这么简单,比oc好用多了,介于个人比较懒,就弄了一个简单的,废话不多说,直接上代码

、、、

import UIKit

class ViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource{

var tableView1 : UITableView?

let dtaArray = ["lettableView1=UITableView(frame:self.view.boundsview.addSubview(tableView1)tableView1.delegatetableView1.dataSourcselftableView1.registerClass(OneTableViewCell.selfforCellReuseIdentifier:OneTableViewCell","23","fadshjfhasdnkjncjxnvfbfjdhkabfdkc nx cmvmxv ajfbskjbdjsd cnmxc ","111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111","fsdfsgfgfd","dssssssfacdavfaddcvvdfafadfsadcxfaa"]

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view, typically from a nib.

self.title = "热门电影"

let tableView1 = UITableView(frame: self.view.bounds)

view.addSubview(tableView1)

tableView1.delegate = self

tableView1.dataSource=self

tableView1.registerNib(UINib(nibName: "TableViewCell",bundle: nil), forCellReuseIdentifier: "TableViewCell")

tableView1.estimatedRowHeight = 44.0

tableView1.rowHeight = UITableViewAutomaticDimension

tableView1.tableFooterView = UIView()

}

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

return self.dtaArray.count

}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell : TableViewCell = tableView.dequeueReusableCellWithIdentifier("TableViewCell") as! TableViewCell

cell.lBEL.text = self.dtaArray[indexPath.row]

return cell

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

、、、

弄的很简单,哈哈

我的cell是用xib制作的

3DDD96B3-74B9-4DDD-BCCD-DE87ACF714F8.png

下面是约束

EBD99F26-C69B-498C-B942-C45AB3619F7E.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值