今天在用swift的時(shí)候用到了cell的自適應(yīng)高度剪返,本來打算運(yùn)用oc的方法,然而卻發(fā)現(xiàn)木有用邓梅,于是在網(wǎng)上各種翻找脱盲,嘿嘿,找到了日缨,原來這么簡單钱反,比oc好用多了,介于個(gè)人比較懶匣距,就弄了一個(gè)簡單的面哥,廢話不多說,直接上代碼
毅待、尚卫、、
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
約束其實(shí)很簡單怎爵,就這樣啦,想知道更細(xì)致的就參考這位大大的http://blog.csdn.net/lengxue789/article/details/47135839