- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在完成所有其他 Stack Overflow 表单之后,我为我的一个单元格实现了动态高度,如下所示:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell
if(indexPath.row == 1){
var image : UIImage = maskRoundedImage(image: UIImage(named: "Temp_Profile.png")!, radius: 150)
cell.imageView?.image = image
return cell
}
cell.textLabel?.text = TableArray[indexPath.row]
cell.backgroundColor = UIColor.init(colorLiteralRed: 0.56, green: 0, blue: 0.035, alpha: 1)
cell.textLabel?.textColor = UIColor.white
cell.textLabel?.font = UIFont(name: "Helvetica", size: 28)
return cell
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.row == 1 {
return UITableViewAutomaticDimension * 3
}
return UITableViewAutomaticDimension
}
这看起来很简单,但调试 session 显示从未调用过 heightForRowAtIndexPath。 View Controller 是一个 UITableViewController,其他一切正常。你们有没有看到这个函数没有被调用的原因?
谢谢你的帮助!
最佳答案
在 Swift 3 中,签名是:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
您有旧签名,因此无法识别。
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 1 {
return UITableViewAutomaticDimension * 3
}
return UITableViewAutomaticDimension
}
关于ios - TableView - heightForRowAtIndexPath 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42006650/
我需要从 tableView:heightForRowAtIndexPath: 访问表格中的单元格因为我想使用客户单元格中的数据来进行高度计算。我发现获取单元格的唯一方法是调用 tableView:c
我很难理解 UITableViewController 的流程。基本上这是我的结构: 我有一个tableViewController,它当然包含一个tableView。在这里,我使用 getCellC
我正在尝试创建一个包含 3 个组的分组 TableView ,每个组都有不同高度的单元格。我在我的 Storyboard 中设置了 3 个具有适当高度的原型(prototype)单元,并设置了我的 U
我有一个包含200-300个不同高度的单元格的表+一个包含UITextView的单元格(该表用于读取和发送消息)。我需要在键入文本时动态调整单元格(包含UITextView)的高度。我使用下一个代码来
我有大约 30 个 View Controller ,它们都有一个实现“heighForRowAtIndexPath”的通用基类。现在我们最近删除了 iOS 7 支持,这让我们可以使用 AutoLay
我正在尝试在我的 tableView 中显示具有正确宽高比的图像。我已经预先计算了图像的长宽比,它似乎在实际图像上正常工作,但在它显示的单元格上却不起作用。 单元格中图像的代码: private va
我想学习一种通用且正确的自定义单元格高度计算方法。 我的单元格是从 nib 加载的,它们有两个多行 UILabels,一个在另一个之上。 目前,我在 viewDidLoad 中创建特殊配置单元格,并在
heightForRowAtIndexPath 函数有一个奇怪的问题。我需要第 3 行的高度更高,但它总是设置下一行(在本例中为第 4 行)的高度。 我会解释: - (CGFloat)tableVie
我正在我的应用中实现聊天功能,并且我正在滚动自己的 UIViewController 来实现此功能。我使用 UITableView 而不是 UICollectionView,因为它更适合我的需求。 我
我在 iOS 应用程序中遇到线程问题。这是一个已经发展了几年的大型应用程序。 (我是这个项目的许多贡献者之一,并且只对它的某些部分有深刻的理解)。 在某些情况下,应用会进行后台刷新,从而触发 tabl
在我的表格 View 中,表格被加载,图像被加载,当图像被加载时,我想从我配置单元格的 ProductTableViewCell.swift 文件再次调用这个函数。 override func tab
我的应用程序有大约 30 个活跃用户和 500 多个注册用户,这个问题只发生在一个使用 iPhone 6 的 9.2 用户身上。 我从崩溃报告中可以看出她已经发生了 60 多次崩溃,并且她说问题有时是
长话短说,iOS8 在 UITableViewAutomaticDimension 上有一个错误 因此,您不能只调用 tableView.rowHeight = UITableViewAutomati
我有一张包含静态单元格的表格。对于一个单元格,我想根据标签的高度(在该单元格内)更改其高度,同时保持所有其他单元格的高度不变。如何获得当前单元格的高度?或者也许有更好的方法? - (CGFloat)t
我有一个表格 View ,我将所有的奇数单元格高度设置为 0,在奇数单元格中我有一些标签。当它显示表格 View 时,奇数单元格中的标 checkout 现在偶数单元格中。有什么办法可以让标签消失吗?
我需要在表格 View 的单元格中加载 HTML。我使用 UIWebView 而不是 UILabel 以便解释 html 标签。WebView 的大小不同,所以我这样做 - (void)webView
我有一个UITableView (分组!)并且需要计算两种样式单元格的高度:UITableViewCellStyleDefault和UITableViewCellStyleValue2 . 我就是这样
在我的 heightForRowAtIndexPath 方法中,我只想为某些行自定义高度。对于其余的事情,我希望框架能够照顾好。我该怎么做? 最佳答案 您可以只返回tableView.rowHeigh
谁能解释一下 tableView:heightForRowAtIndexPath 方法的生命周期。这个方法在什么时候被调用。 第一次填充 TableView 时的示例。 除此之外,任何时候调用此方法?
我正在尝试在 UITableViewController 中使用 heightForRowAtIndexPath 方法。但是当我尝试重写该方法时,它说它不会重写其父类(super class)中的任何
我是一名优秀的程序员,十分优秀!