Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在swift中调整自定义单元格大小时遇到问题_Ios_Swift_Uitableview - Fatal编程技术网

Ios 在swift中调整自定义单元格大小时遇到问题

Ios 在swift中调整自定义单元格大小时遇到问题,ios,swift,uitableview,Ios,Swift,Uitableview,因此,我使用解析后端构建了一个简单的messenger。在表格视图中,我显示了用户之间的对话。tableView中的单元格根据标签上的文本量调整大小 我在viewDidLoad()中使用此代码来实现调整大小: tableView.estimatedRowHeight = 51 tableView.rowHeight = UITableViewAutomaticDimension tableView.setNeedsLayout() tableView.layoutIfNeeded() 我使用的

因此,我使用解析后端构建了一个简单的messenger。在
表格视图中
,我显示了用户之间的对话。
tableView
中的单元格根据标签上的文本量调整大小

我在
viewDidLoad()
中使用此代码来实现调整大小:

tableView.estimatedRowHeight = 51
tableView.rowHeight = UITableViewAutomaticDimension
tableView.setNeedsLayout()
tableView.layoutIfNeeded()
我使用的估计高度为51,因为这是我在故事板上的单元高度。 不管怎么说,我面临的问题是,有时单元格大小不合适,有时看起来太大,无法容纳所容纳的内容。我不明白为什么。这是对单元格的不正确渲染

这是我通过简单地上下滚动实现的对单元格的稍微正确的渲染


这里发生了什么?

请看本教程:好的,我看了本教程,它让我了解了我可能做错了什么,但是,在遵循了提供的一些建议之后,我仍然面临着同样的问题,一些细胞决定太大。。谢谢@madmir,TWA是一个很好的资源。不幸的是,这不会改变什么。
remove this lines from viewDidLoad

1)tableView.estimatedRowHeight = 51
2)tableView.rowHeight = UITableViewAutomaticDimension

use below two methods of tableview

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

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