0
我想調用Swift 3.0中的委託函數。在調用時,我得到一個錯誤,其中指出「致命錯誤:意外地發現零,同時解開一個可選值」。我已經通過給靜態值,動態值沒有用。Swift代表調用致命錯誤
protocol getServiceDelegate{
func getService(_ ServiceTitle: String)
}
我以下面的方式調用這個代表。
self.delegate.getService("hello")
我在這裏做什麼錯了。下面我設置代表。
func textServiceTapped(img: AnyObject)
{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "ProviderMoreDetailsVC") as! ProviderMoreDetailsViewController
vc.delegate = self
navigationController?.pushViewController(vc,
animated: true)
}
func getService(_ ServiceTitle: String){
textService.text = ServiceTitle
}
可能是你忘了設置在那裏正在實施其委託解決錯誤。 –
不,已經設置了代理 – user2702179
然後你需要顯示那個代碼。 –