【发布时间】:2016-04-04 23:45:04
【问题描述】:
我正在尝试使用占位符从远程源将imageView 设置为标准UITableViewCell。无论使用SDWebImage 或AlamofireImage 作为库,我都会遇到这个问题。
这是单元格在初始加载后的显示方式:
然后,一旦点击/重新加载单元格,它就会显示为:
在情节提要中,我将行高调整为 60 磅,而不是标准的 44 磅。如果我将高度恢复为标准的 44 点,则问题不再存在。
我认为这个问题更多地与单元格的自定义高度有关,而不是与提供占位符的库有关。我在AlamofireImage in case it was a problem with the library 上提出了问题,但事实证明并非如此。
我如何才能将图像初始设置为正确的大小,或防止在重新加载时发生调整大小?
这是来自我的UITableViewCell 子类的代码。请注意,即使我删除了 layoutSubviews 内的框架插入代码,也会出现问题。
class CategoryTableViewCell: UITableViewCell {
var category: Category! {
didSet {
self.updateCategory(category)
}
}
override func layoutSubviews() {
super.layoutSubviews()
self.imageView?.frame = CGRectInset(self.imageView!.frame, 10, 10)
}
private func updateCategory(category: Category) {
self.textLabel?.text = category.name
self.imageView?.sd_setImageWithURL(category.largeImage ?? nil, placeholderImage: UIImage(named: "DefaultCategory"))
}
}
我现在还在表格视图控制器上设置了以下覆盖,但它没有任何效果。
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 60;
}
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 60;
}
【问题讨论】:
-
你有代码要分享吗?你在用
UITableViewCell子类(如果有的话)做任何“时髦”的事情吗?界面生成器中有任何冲突的约束吗? -
尝试将tableview的
heightForRowAtIndexPath设置为60。或estimatedHeightForRowAtIndexPath -
我已经从我的子类中添加了代码。此外,没有冲突的约束。
-
我已经添加了如上图所示的两个高度代理,但是它们没有任何效果。
-
@Dwight 我也有同样的问题,你找到解决办法了吗?
标签: ios swift uitableview