mack mack - 1 month ago 4
iOS Question

Data are not showing in label

I have one collection view which have to display only the category name and its image. And if user click any collection view cell, It will go to next vc and it will show the respective name, images.

But when i pass the value to my label its not showing in my screen. But while put print statement. It showing the value.Here is my code

My first vc segue :

override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{

if (segue.identifier == "CollectionToDetail")
{

if let indexPath2 = getIndexPathForSelectedCell2()
{
let DealsdetailViewController = segue.destination as!MoreDetailVC

DealsdetailViewController.Productdata = [Productdata[(indexPath2 as NSIndexPath).row]]

print(Productdata[(indexPath2 as NSIndexPath).row].catID)
}
}

}


In my second VC :

var Productdata = [ProductData]()
override func viewDidLoad() {
super.viewDidLoad()

ProductName.text = Productdata[0].catName

print(ProductName.text)
}


But my
ProductName.text = Productdata[0].catName
is not showing any value on my screen . please help me out.

Thanks

Answer

In my second VC :

    override func viewDidLoad() {
        super.viewDidLoad()
        //self.ProcatId = Productdata[0].catID

      //  print(self.ProcatId)
        ProductName.text = self.Productdata[0].catName

        print(ProductName.text)

 GetAdValues()

}
 func GetAdValues()
    {
        ProductName.text = Productdata[0].catName!

        print(ProductName.text)

        self.load_image((Productdata[0].proImage)!)

      //  let BDetails = Dealsdata?.DealBusinessDetails

      //  self.BusinessData.append(Businessdata(json:BDetails!))

    }
func load_image(_ urlString:String)
    {
        let imgURL: URL = URL(string: urlString)!

        let request: URLRequest = URLRequest(url: imgURL)

        let session = URLSession.shared

        let task = session.dataTask(with: request, completionHandler: {
            (data, response, error) -> Void in

            if (error == nil && data != nil)
            {
                func display_image()
                {
                    self.ProductImage.image = UIImage(data: data!)
                }

                DispatchQueue.main.async(execute: display_image)
            }

        })

        task.resume()
    }

output

Comments