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

约束其实很简单,就这样啦,想知道更细致的就参考这位大大的http://blog.csdn.net/lengxue789/article/details/47135839

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

推荐阅读更多精彩内容

  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,216评论 30 472
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,251评论 4 61
  • 7、不使用IB是,下面这样做有什么问题? 6、请说说Layer和View的关系,以及你是如何使用它们的。 1.首先...
    AlanGe阅读 719评论 0 1
  • 【作者】张秋菊 【课程导师】刘艳 【导图解说】 激动人心的夏令营马上就要拉开帷幕啦,针对6、7、8三个月就有了一定...
    海鸥ing阅读 337评论 0 1
  • 《学习之道》第二章主要讲了专注思维和发散思维的的概念。 这两个思维模式都有各自的优缺点。专注思维模式下,你更容易...
    super鹅阅读 369评论 0 0