所以基本上我将文本从数组加载到表视图中的单元格中,但不是像我想要的那样继续到下一行,而是输入的文本标签在单个单元格中从屏幕上被截断。我在网上查了一下,据说将 numberOfLines 设置为 0,将 lineBreakMode 设置为 NSLineBreakingByWordWrapping,但它不起作用。我究竟做错了什么?谢谢!
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "homeSeries", for: indexPath)
// Configure the cell...
cell.textLabel?.text = dataArrayRelease[indexPath.row] + " " + dataArraySeries[indexPath.row] + " by " + dataArrayGroup[indexPath.row]
cell.textLabel?.numberOfLines = 0
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping
return cell
}
Your cellForRowAt
方法代码正确。你需要做一些与行高相关的事情。
将表格视图行高设置为UITableViewAutomaticDimension
in viewDidLoad()
method.
yourTableview.rowHeight = UITableViewAutomaticDimension
yourTableview.estimatedRowHeight = 44
OR
你可以添加波纹管UITableViewDelegate
控制器中的方法
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 44
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)