0
 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if collectionView.tag == 2{

            switch indexPath.item {
            case 0:
               if let vc = storyboard?.instantiateViewController(withIdentifier: "offersScreen") as? OffersVC {
                vc.cityID = self.cityID!
                vc.categoryID = indexPath.item + 1
                vc.headingLBL.text =  self.names[indexPath.item]
                vc.cityLBL.text = self.selectCity.text!
                    present(vc, animated: true, completion: nil)
                }   
            case 1:
                print("You're heading VC 1!")
            case 2:
                print("You're heading VC 2!")
            case 3:
                print("You're heading VC 3!")
            default:
                print("Something went wrong")
            }
        }
    }

enter image description here

I wrote everything perfect idk what I made mistake. It found nil value on on present. I present viewcontroller from tabbar viewController with 4 values Please help or guide. Thanks in advance.

2 Answers2

1

Reason is all outlets are nil until the vc loads

options #1

 vc.loadViewIfNeeded()
 vc.headingLBL.text =  self.names[indexPath.item]

options #2

make vars of what you need to send

class OffersVC:UIViewController {
   var sendedStr = ""

then inside viewDidLoad

self.headingLBL = sendedStr
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
1

Looking at your image description, I think the problem is that you are trying to unwrap 'headingLBL' without first initialising it.

See Swift Xcode "EXC_BAD_INSTRUCTION"

Vedant
  • 339
  • 4
  • 10