我试图使用variabes更新另一个类中的视图,但是由于某些奇怪的原因,我得到了一个fatal error: unexpectedly found nil while unwrapping an Optional value。从存在视图的页面调用该函数,但在其他任何地方都不起作用。我做错什么了吗?

     func updateView(trackName: String, image: UIImage){
    let view = IntroController()
    view.cardLabel.text = trackName
    view.cardImage.image = image
}




 func startProcess(completionHandler: (Bool) -> ()) -> (){
            getUserData{
                msg in
                if (msg){
                    print("STEP 1: Get User Data Complete")
                    self.getSearchTerms{
                        termRtn in
                        if (termRtn){
                            print("STEP 2: Get Search Terms Complete")
                            self.searchTerms = self.createArray()
                            self.search{
                                msg in
                                if (msg){
                                    print("STEP 3: Search Completed!")
                                    print(parResults.count)
                                    self.downloadImages{ dlComplete in
                                        if (dlComplete){

                                            print("STEP 4: CardImage has been downloaded or created")
                     updateView(trackName: "test1", image: UIImage(named: "test");
                                            completionHandler(true)
                                        }
                                    }

                                }
                            }

                        }
                    }
                }
            }
        }

最佳答案

由于您没有提供太多代码,因此我仍然会尝试回答。您实例化的IntroController可能在其构造函数中没有任何代码可加载实际的XiB。因此,您尝试引用尚未加载其视图的IntroController的view属性。如果需要更多帮助,请发布IntroController的内容。

10-07 14:33