2017-07-15 68 views

回答

0

当然,

这里是苹果的文档Working with Self Sizing TableViewCells

首先,你的应适当设置了限制。

第二,在你的浏览器,你应该写在

self.tableView.rowHeight = UITableViewAutomaticDimension 
self.tableView.estimatedRowHeight = 44.0 // non zero value 

viewDidLoad()

或者你可以返回不同高度形成的委托方法 func tableView(UITableView, heightForRowAt: IndexPath)

0

你绝对可以做到这一点,

确保您的两个单元格都具有足够的自动尺寸。

在你所在班级使用tableViewviewDidLoad中写下这两行。

//as per your table Outlet name, in my case it's tableView 

tableView.rowHeight = UITableViewAutomaticDimension 
tableView.estimatedRowHeight = 36.0 

或者,您也可以在UITableView方法中定义高度。

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
     // Your cell Height 
    } 
0

你有两种方法可以做到这

  1. 从UITableView的方法

    FUNC的tableView(_的tableView:UITableView的,heightForRowAt indexPath: IndexPath) - > CGFloat的 在这方法可以设置相对于每个单元格的高度 对于 “indexpath.row”

  2. UITableViewAutomaticDimension 在viewDidLoad中或其他初始方法写这样

    self.tableView.rowHeight = UITableViewAutomaticDimension self.tableView.estimatedRowHeight = 44

相关问题