0

Have an issue when sending the imageURL to anotherViewController the error is like ( Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value).I'm using messageKit and SdWEbImage pod.When user click on image it goes to photoViewController and image will show.

ChatDashobard Controller:

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
        }
    }
}

PhotoViewController:

@IBOutlet weak var productImage: UIImageView!
    var imageUrL:URL? = nil
    
    override func viewDidLoad() {

        if let getImageFromURL = imageUrL{
            productImage.sd_setImage(with:getImageFromURL,completed:nil)
        }
    }
    

enter image description here

Faheem
  • 97
  • 5
  • You should probably be calling `super.viewDidLoad()` although I don't think it'll fix your issue. – Owen Oct 02 '21 at 15:20
  • It sounds like your issue is with the `productImage` UIImageView. Set a breakpoint on line 21 when the line is hit run the command `po productImage` in the console (where it says `lldb`) if it's nil then that's your problem. – Owen Oct 02 '21 at 15:25

0 Answers0