将 imageURL 发送到 anotherViewController 时出现问题,错误类似于(致命错误:在隐式展开可选值时意外发现 nil)。我正在使用 messageKit 和 SdWEbImage pod。当用户单击图像时,它会转到 photoViewController 并且图像将显示.
ChatDashobard 控制器:
extension ChatDashboard:MessageCellDelegate{
// MARK:- Working only for image
func didTapImage(in cell: MessageCollectionViewCell) {
guard let indexPath = messagesCollectionView.indexPath(for: cell) else {return}
self.configureImageVeiwController(messagesData: self.messages[indexPath.section])
}
func configureImageVeiwController(messagesData:Message){
let messages = messagesData.kind
switch messages {
case .photo(let media):
guard let imageURL = media.url else {
return
}
let photoCotroller = PhotoViewController()
photoCotroller.imageUrL = imageURL
self.navigationController?.pushViewController(photoCotroller, animated: true)
default:
break
}
}
}
照片视图控制器:
@IBOutlet weak var productImage: UIImageView!
var imageUrL:URL? = nil
override func viewDidLoad() {
if let getImageFromURL = imageUrL{
productImage.sd_setImage(with:getImageFromURL,completed:nil)
}
}