swift UITableView cell自适应高度

swift UITableView cell自适应高度

ios8支持:

1.

override func viewDidLoad() {  
    super.viewDidLoad()  
      
    self.tableView.estimatedRowHeight = 100  
    self.tableView.rowHeight = UITableViewAutomaticDimension  
} 

2.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {  
......  
            cell.textLabel?.numberOfLines = 0  
            cell.textLabel?.preferredMaxLayoutWidth = CGRectGetWidth(tableView.bounds)  
} 

3.

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {  
    return UITableViewAutomaticDimension  
}