我有两个视图控制器 - A& B. ViewController A有一个文本字段。点击ViewController A的文本字段,出现View Controller B,它有另一个Textfield。在ViewController B的键盘上单击完成,调用dissmissViewController,textfield的数据应从viewController B移动到A.
我无法将数据从B传递到A.我会在dissmissviewcontroller之前调用A的ViewdidLoad()。在A的viewdidLoad()中,我有这个textfieldA.text = textfieldB。它在扔 -
致命错误:在展开可选值"
时意外发现nil
答案 0 :(得分:1)
委托模式:
<强> ViewController2:强>
means = c(paste("mean_Age =",roumean(survey_clean_data[Smoke == "Heavy","Age"],na.rm =T)),
paste("mean_Age =",mean(survey_clean_data[Smoke == "Never","Age"],na.rm =T)),
paste("mean_Age =",mean(survey_clean_data[Smoke == "Regul","Age"],na.rm =T)),
paste("mean_Age =",mean(survey_clean_data[Smoke == "Occas","Age"],na.rm =T)))
text(50,survey_clean_data$Smoke,labels = means)
<强> ViewController1:强>
//Define Protocol
@protocol VC2Delegate {
doneClicked(val:String)
}
Class:VC2 {
//Create Delegate variable
var delegate:VC2Delegate?
//method of done clicked
func btnDoneClicked(sender:UIButton) {
//call delegate method
delegate.doneClicked(vc2TextField.text)
//dismiss view controller
self.dismissViewController......
}
}