[英]Updating image in Chat bubble using Chatto library ios
我已经在现有模型中添加了Chatto for UI,因此我可以使用占位符创建消息,但无法找出下载后更改相同消息的最佳方法。
图书馆链接https://github.com/badoo/Chatto
我正在使用带有DemoPhotoMessageModel的chatto测试应用程序。 然后我用下面的添加
var imgMess = DemoPhotoMessageModel(messageModel: messageModel, imageSize: placeholder.size, image: placeholder)
self.slidingWindow.insertItem(imgMess, position: .bottom)
self.delegate?.chatDataSourceDidUpdate(self)
ImageDownloader.default.downloadImage(with: downloadURL, options: [], progressBlock: nil) {[unowned self]
(image, error, url, data) in
print("Downloaded Image: \(image)")
if let img = image, let imgData = UIImagePNGRepresentation(img){
imgMess.setImage(img: img) //I updated the default implementation changing the image from var to let constant
}
}
我还尝试过的方法是在slideWindow本身中更新对象。 那也行不通。 用新的uid或其他任何东西创建新对象的可能解决方案是什么。
您可以在视图模型的willBeShown()
方法中下载图像。 由于需要传递url来查看模型,因此需要将几个类子类化。 请查看要点的完整解决方案。 请随时提出任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.