'My CollectionViewController did not shows the DetailViewController. When Simultaneously clicking it shows the DetailViewController

DetailViewController is not working and its my storyboard

CountryCollectionViewController

import Foundation
import UIKit

private let reuseIdentifier = "Cell"

class CountryCollectionViewController: UICollectionViewController {
    
    
    
    @IBAction func unwindToMain(segue: UIStoryboardSegue){
        
    }
    
    private var countries : [Country] = [ Country(image: "America", name: "America", text: "1. What is the Official Languages for America? \n Answer:- English.\n\n 2. What is the Capital city for United States of America? \n Answer:-  Washington, D.C.\n\n 3. What is the Currency for United States of America?? \n Answer:-  American Doller."),                     
        Country(image: "Vietnam", name: "Vietnam", text: "1. What is the Official Languages for Vietnam? \n Answer:-  Vietnamese.\n\n 2. What is the Capital city for Vietnam? \n Answer:-  Hanoi.\n\n 3. What is the Currency for Vietnam? \n Answer:-  Vietnamese dong.")]
    
    @IBOutlet var sideMenuBtn: UIBarButtonItem!


    override func viewDidLoad() {
        super.viewDidLoad()
        
        sideMenuBtn.target = self.revealViewController()
        sideMenuBtn.action = #selector(self.revealViewController()?.revealSideMenu)

    }

    // MARK: UICollectionViewDataSource

    override func numberOfSections(in collectionView: UICollectionView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }


    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of items
        return countries.count
    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "dataCell", for: indexPath) as! CountryCollectionViewCell
    
        // Configure the cell
        
        let country = countries[indexPath.row]
        cell.countryImageView.image = UIImage(named: country.image)
        cell.countryNameLabel.text = country.name
    
        return cell
    }
    
    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        collectionView.deselectItem(at: indexPath, animated: false)
        performSegue(withIdentifier: "showDetail", sender: indexPath)
        
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        guard segue.identifier == "showDetail" else {
            return
        }
             let indexPath = sender as! IndexPath
                let destinationController = segue.destination as! CountryDetailViewController
                destinationController.country = countries[indexPath.row]
                //collectionView.deselectItem(at: indexPaths[0], animated: false)
            }
        }

CountryDetailViewController

import Foundation
import UIKit

class CountryDetailViewController: UIViewController {
    
    @IBOutlet var countryImageView:UIImageView!
    @IBOutlet weak var countryTextView: UITextView!
    @IBOutlet weak var countryLabel: UILabel!
    
    var country: Country!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        countryLabel.text = country.name
        countryTextView.text = country.text
        countryImageView.image = UIImage(named: country.image)
    }
}

I'm new to xcode. My DetailViewController is not showing, IDK for why. If I try this example in separate project its works fine but, If I try this with my big project then it CountryCollectionViewController is loading but not DetailViewController. If I click simultaneously then only it displays. Can anyone Please help me from this issue. I attached my constraints errors also. Thanks in advance

2022-02-19 23:15:52.155204+0100 MultiTasker[20055:4485282] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x2804f83c0 UIImageView:0x141d63480.width == 100   (active)>",
    "<NSLayoutConstraint:0x2804fa530 H:|-(0)-[UIImageView:0x141d63480]   (active, names: '|':UIView:0x141d62f30 )>",
    "<NSLayoutConstraint:0x2804fa4e0 H:[UIImageView:0x141d63480]-(0)-|   (active, names: '|':UIView:0x141d62f30 )>",
    "<NSLayoutConstraint:0x2804f8b40 'UIIBSystemGenerated' MultiTasker.CountryCollectionViewCell:0x141d62ce0.leading == UIView:0x141d62f30.leading   (active)>",
    "<NSLayoutConstraint:0x2804fd0e0 'UIIBSystemGenerated' H:[UIView:0x141d62f30]-(0)-|   (active, names: '|':MultiTasker.CountryCollectionViewCell:0x141d62ce0 )>",
    "<NSLayoutConstraint:0x2804945a0 'UIView-Encapsulated-Layout-Width' MultiTasker.CountryCollectionViewCell:0x141d62ce0.width == 50   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x2804f83c0 UIImageView:0x141d63480.width == 100   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2022-02-19 23:15:52.156062+0100 MultiTasker[20055:4485282] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x2804fa620 UILabel:0x141d63650.width == 100   (active)>",
    "<NSLayoutConstraint:0x2804fa3f0 H:[UILabel:0x141d63650]-(0)-|   (active, names: '|':UIView:0x141d62f30 )>",
    "<NSLayoutConstraint:0x2804f9a40 H:|-(0)-[UILabel:0x141d63650]   (active, names: '|':UIView:0x141d62f30 )>",
    "<NSLayoutConstraint:0x2804f8b40 'UIIBSystemGenerated' MultiTasker.CountryCollectionViewCell:0x141d62ce0.leading == UIView:0x141d62f30.leading   (active)>",
    "<NSLayoutConstraint:0x2804fd0e0 'UIIBSystemGenerated' H:[UIView:0x141d62f30]-(0)-|   (active, names: '|':MultiTasker.CountryCollectionViewCell:0x141d62ce0 )>",
    "<NSLayoutConstraint:0x2804945a0 'UIView-Encapsulated-Layout-Width' MultiTasker.CountryCollectionViewCell:0x141d62ce0.width == 50   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x2804fa620 UILabel:0x141d63650.width == 100   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2022-02-19 23:15:52.156706+0100 MultiTasker[20055:4485282] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x2804f99f0 UIImageView:0x141d63480.height == 115   (active)>",
    "<NSLayoutConstraint:0x2804fa5d0 UILabel:0x141d63650.height == 35   (active)>",
    "<NSLayoutConstraint:0x2804fa490 V:|-(0)-[UIImageView:0x141d63480]   (active, names: '|':UIView:0x141d62f30 )>",
    "<NSLayoutConstraint:0x2804fa440 V:[UILabel:0x141d63650]-(0)-|   (active, names: '|':UIView:0x141d62f30 )>",
    "<NSLayoutConstraint:0x2804fa1c0 V:[UIImageView:0x141d63480]-(0)-[UILabel:0x141d63650]   (active)>",
    "<NSLayoutConstraint:0x2804fd090 'UIIBSystemGenerated' MultiTasker.CountryCollectionViewCell:0x141d62ce0.top == UIView:0x141d62f30.top   (active)>",
    "<NSLayoutConstraint:0x2804fd040 'UIIBSystemGenerated' V:[UIView:0x141d62f30]-(0)-|   (active, names: '|':MultiTasker.CountryCollectionViewCell:0x141d62ce0 )>",
    "<NSLayoutConstraint:0x2804945f0 'UIView-Encapsulated-Layout-Height' MultiTasker.CountryCollectionViewCell:0x141d62ce0.height == 50   (active)>"
)


Solution 1:[1]

I looked at your storyboard and I think the problem is in the second navigation controller. I tried to reproduce as much of your app as possible and the app crashes when I have the navigation controller between the CountryCollectionViewController and the CountryDetailViewController.

This navigation controller is not necessary anyway. Can you delete this navigation controller and see if your code works better?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 halfer