2017-01-05 90 views
0

我有很多customCells每个小区可以有一个按钮,它的作用就像一个文本框或textArea.When查看负载他们有非常少的高度。无法设置CustomCells的高度在迅速

override func viewDidLoad() { 

    super.viewDidLoad(); 

    self.view.backgroundColor = UIColor.groupTableViewBackground 
    self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none 
    self.tableView.estimatedRowHeight = 100 
    tableView.rowHeight = UITableViewAutomaticDimension 
    self.tableView.setNeedsLayout() 
    self.tableView.layoutIfNeeded() 

} 

,我已经对细胞enter image description here

将与原型细胞的功能自动布局工作规定以下约束? 如果不是如何实现这个? 我HeightforrowAtIndexPath方法布局仅试图滚动后看起来不错。视图的初始加载不会具有良好的布局。下面

是我对这段代码。

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
    if (eleData.elementType=="apple") 
    { 
     return 90; 
    } 
else if (eleData.elementType=="banana") 
    { 
     return 50; 
    }  
else 
{ 
    return 30; 
} 

} 

有什么建议。 预先感谢您。

回答

1

快速谷歌搜索给你答案......

UITableView dynamic cell heights only correct after some scrolling

您需要添加布局,如果需要cellForRowAtIndexPath方法中返回你的面前:

cell.layoutIfNeeded() 
+0

太谢谢你了。它的工作现在很好。 – Dev

+0

不客气! –

+0

有时仍然会同样的问题来了...我怎样才能避免这种情况? – Dev