Problem with collectionView

0

Hello, good afternoon.

I'm facing a problem with collectionview swift, it just does not appear, I do not quite understand this issue, but it does not get into the cell collectionView routine, I do not know if it's really working well, so I'd like to tell with your help, below I'll put the code I'm using from the collectionView:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {


        //   let cell = collectionView.cellForItemAtIndexPath(indexPath) as! CarCollectionViewCell
        //   cell.container.layer.backgroundColor = UIColor.lightGrayColor().CGColor

        //let cell = collectionView.cellForItem(at: indexPath) as! CarCollectionViewCell




        checkvaluecollectioncell = indexPath.row

        self.selectvalue = 1

        self.markers.removeAll()
        self.driverIds.removeAll()




       if(UserDefaults.standard.object(forKey: "PreferredLanguage") as! String == "en"){

            GlobalVarible.firstcarname = CarsTimedata.details![indexPath.row].carTypeName!
            GlobalVarible.cartypename = CarsTimedata.details![indexPath.row].carTypeName!
        }else{
            GlobalVarible.firstcarname = CarsTimedata.details![indexPath.row].carTypeName!
            GlobalVarible.cartypename = CarsTimedata.details![indexPath.row].carTypeName!
        }

        GlobalVarible.car_type_id = CarsTimedata.details![indexPath.row].carTypeId!


        GlobalVarible.cartypeid = CarsTimedata.details![indexPath.row].carTypeId!

        GlobalVarible.Cityid = CarsTimedata.details![indexPath.row].cityId!

        // aqui caminho imagem - 20/10/2018
        GlobalVarible.cartypeimage = CarsTimedata.details![indexPath.row].carTypeImage!


        if CarsTimedata.details![indexPath.row].rideMode == "2"{

            print("ridemode2")

            ApiManager.sharedInstance.protocolmain_Catagory = self
            ApiManager.sharedInstance.SelectRentalCar(CityID: GlobalVarible.Cityid)

        }else{
            self.mapview.clear()
             self.postdata.removeAll()
            self.datagetfromgeofire()
           //21/10/2018
            //self.GetDatafromfirebase()

        }

        MapCollectionview.reloadData()


    }

And I have another cell collectionView routine that is below:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = MapCollectionview.dequeueReusableCell(withReuseIdentifier: "Mapcollectioncell", for: indexPath) as! CarCollectionViewCell



        cell.container.layer.shadowColor = UIColor.gray.cgColor
        cell.container.layer.shadowOpacity = 1
        cell.container.layer.shadowOffset = CGSize(width: 0, height: 2)
        cell.container.layer.shadowRadius = 2

          //  .addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)

        let newString = CarsTimedata.details![indexPath.row].carTypeImage!
        print(newString)


        let url = imageUrl + newString


        let alerta = UIAlertController(
            title: "Falha de Comunicação",
            message: url,
            preferredStyle: .alert)

        present(alerta, animated: true, completion: nil)



        let url1 = NSURL(string: url)

        cell.carimage!.af_setImage(withURL:
            url1! as URL,
            placeholderImage: UIImage(named: "dress"),
            filter: nil,
            imageTransition: .crossDissolve(1.0))


        if(checkvaluecollectioncell == indexPath.row)
        {


           // cell.container.layer.backgroundColor =  (UIColor(red: 179.0/255.0, green: 191.0/255.0, blue: 191.0/255.0, alpha: 1.0) as! CGColor)
         //   cell.container.layer.backgroundColor = UIColor.lightGray.cgColor

            cell.container.backgroundColor = UIColor(red:147.0/255.0, green:165.0/255.0, blue:165.0/255.0, alpha:1.0)

            cell.carname.textColor = UIColor.white
            cell.cartime.textColor = UIColor.white
            //21/10/2018
             //cell.checkRadioBtn.image = UIImage(named: "Circled Dot-35 (1)")

        }else{

            cell.container.backgroundColor = UIColor.white
            cell.carname.textColor = UIColor(red:147.0/255.0, green:165.0/255.0, blue:165.0/255.0, alpha:1.0)
            cell.cartime.textColor = UIColor(red:243.0/255.0, green:156.0/255.0, blue:18.0/255.0, alpha:1.0)
            // cell.checkRadioBtn.image = UIImage(named: "Circle Thin-35 (1)")

        }


        cell.carname.text = CarsTimedata.details![indexPath.row].carTypeName!

        cell.cartime.text = CarsTimedata.details![indexPath.row].baseFare!


        return cell

    }


Eu chamo a rotina assim:

                let indexPathForFirstRow = IndexPath(row: 0, section: 0)
                self.collectionView(MapCollectionview, didSelectItemAt: indexPathForFirstRow)


Porem ele não entra na rotina do collectionView Cell, como falei não entendo muito bem como funciona então não sei se é assim mesmo o funcionamento, porem ele so entra na outra rotina do collectionView que é essa:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 

and consequently does not access the routine data that is in the Cell collectionView

If anyone could help me, it would be nice.

    
asked by anonymous 22.10.2018 / 20:29

1 answer

0

In class definition, you should implement UICollectionViewDelegate and UICollectionViewDataSource and somewhere, for example in viewDidLoad collectionview.delegate = self

Also see if your collectionView has the right constraints on the screen so that it is visible enough to show any items. If the collectionView is not set to size, width defined may not be called cellForItemAt .

    
24.10.2018 / 20:31