为什么在 UITableViewCell 中使用 SDWebImage 会触发 ImageViews 无法正确呈现?
Why using SDWebImage in a UITableViewCell triggers ImageViews not to render properly?
我有一个 UITableViewController,其中包含我在 cellForRowAtIndexPath 中出列的我自己的单元格。
出队后,我配置单元格并异步重新加载该单元格的图像。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCellWithIdentifier("PeopleCell", forIndexPath: indexPath) as? PeopleListViewCell {
cell.configureCell(headImageUrl)
}
}
在我的 PeopleListView 中 class,
func configureCell(img:NSURL) {
if headImageView == nil { // to avoid allocation memory if not used
headImageView = UIImageView()
addSubView(headImageView)
}
headImageView.sd_cancelCurrentImageLoad()
headImageView.sd_setImageWithURL(headImageUrl)
}
它在第一次加载和滚动时工作正常。
但是当我在
之后推另一个 viewController
didSelectRowAtIndexPath
并在
之后返回列表
dismissViewController()
我最终在我的 UIImageView 上产生了奇怪的效果,它是一种堆叠或重影图像效果..
当我从 viewController 返回时,我很难弄清楚触发的位置,未调用 cellForRowAtIndexPath。
这其实和异步图片加载没有关系。
我的图像显示在圆圈内,带有 cornerRadius。
不知何故,它在第一次加载时显示没有任何问题...
这里的问题是我忘记了
headImageView.layer.maskToBounds = true
我在将maskToBounds 设置为true 之前得到的结果是,我有多个图像位于headImageView (UIImageView) 中的感觉。如果你曾经有过这样的手工艺品,我希望这篇 question/answer 能对你有所帮助。
我有一个 UITableViewController,其中包含我在 cellForRowAtIndexPath 中出列的我自己的单元格。 出队后,我配置单元格并异步重新加载该单元格的图像。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCellWithIdentifier("PeopleCell", forIndexPath: indexPath) as? PeopleListViewCell {
cell.configureCell(headImageUrl)
}
}
在我的 PeopleListView 中 class,
func configureCell(img:NSURL) {
if headImageView == nil { // to avoid allocation memory if not used
headImageView = UIImageView()
addSubView(headImageView)
}
headImageView.sd_cancelCurrentImageLoad()
headImageView.sd_setImageWithURL(headImageUrl)
}
它在第一次加载和滚动时工作正常。
但是当我在
之后推另一个 viewControllerdidSelectRowAtIndexPath
并在
之后返回列表dismissViewController()
我最终在我的 UIImageView 上产生了奇怪的效果,它是一种堆叠或重影图像效果.. 当我从 viewController 返回时,我很难弄清楚触发的位置,未调用 cellForRowAtIndexPath。
这其实和异步图片加载没有关系。 我的图像显示在圆圈内,带有 cornerRadius。 不知何故,它在第一次加载时显示没有任何问题...
这里的问题是我忘记了
headImageView.layer.maskToBounds = true
我在将maskToBounds 设置为true 之前得到的结果是,我有多个图像位于headImageView (UIImageView) 中的感觉。如果你曾经有过这样的手工艺品,我希望这篇 question/answer 能对你有所帮助。