PresentViewController在instantiateViewController上找到nil值

问题描述 投票:0回答:2
 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

我把一切都写了完美的idk我弄错了。目前发现零值。我从标签栏viewController呈现viewcontroller具有4个值请帮助或指导。预先感谢。

swift uiviewcontroller storyboard presentviewcontroller
2个回答
0
投票

原因是所有出口都为零,直到vc加载为止

选项#1

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

选项#2

制作需要发送的内容

class OffersVC:UIViewController {
   var sendedStr = ""

然后在viewDidLoad

self.headingLBL = sendedStr

0
投票

[查看您的图像描述,我认为问题是您试图在不首先对其进行初始化的情况下展开'headingLBL'。

请参见Swift Xcode "EXC_BAD_INSTRUCTION"

© www.soinside.com 2019 - 2024. All rights reserved.