2016-02-29 56 views
0

我加載視圖控制器作爲一個子視圖一個UIScrollView的內部。下面的代碼的偉大工程,直到我嘗試過,應用程序崩潰與消息設置在控制器的@IBOutlet的價值負載的ViewController內的UIScrollView

fatal error: unexpectedly found nil while unwrapping an Optional value 

這是我的代碼:

let controller:ReportPageOneViewController = self.storyboard!.instantiateViewControllerWithIdentifier("report_page_one") as! ReportPageOneViewController 
addChildViewController(controller) 

controller.titleLabel.text = "This is some text. Hope it works"// App crashes here 



detailsView.addSubview(controller.view) 
view.addSubview(detailsView) 

感謝

+1

我不知道設置的變量值(和無法測試...),但我認爲你應該通過文字在一個變量,並在ReportPageOneVie中wController,viewWillAppear將文本設置爲titleLabel.text。 – UlyssesR

+0

您的建議完美。謝謝! –

+0

我很高興它幫助:) – UlyssesR

回答

0

對於任何需要解決方案的人,請參閱上面的第一條評論。

創建一個新的變種titleValue =字符串

這應該是在視圖控制器,然後在viewWillAppear中設置的出口值到可變

titleLabel.text = titleValue

在主控制器與uiscroll視圖中,您可以接着使用controller.titleValue =「任何你喜歡」