【发布时间】:2018-06-24 23:15:01
【问题描述】:
我尝试为动态内容设置单元格高度。在单元格中,我使用了两个 UILabel,但我无法从 tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) 访问单元格。正如 tableview 显示的那样,img 中有单元格,但是当我在模拟器中运行应用程序时,print("Cell geted") 没有输出任何内容。 我只是IOS开发的初学者,所以我的应用程序中可能有一些错误的配置。我想知道什么原因会导致这种情况
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let cell = self.tableView.cellForRow(at: indexPath) as? ArticleTableViewCell
if(cell != nil) {
print("Cell geted")
}
return 120
}
我使用 xib 文件来定义单元格
Comtum 细胞类如下
import UIKit
class ArticleTableViewCell: UITableViewCell {
@IBOutlet weak var time: UILabel!
@IBOutlet weak var digest: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
time.layer.borderWidth = 1
//time.layer.masksToBounds = true
time.layer.cornerRadius = 10
time.backgroundColor = UIColor.cyan
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
故事板xib文件如下
【问题讨论】:
标签: ios swift uitableview autolayout row-height